[백준] 2920 . 음계
Algorithm2021. 11. 7. 14:09
반응형
2920번: 음계
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8
www.acmicpc.net
Boyer-Moore 알고리즘의 아이디어를 따와 풀었다.
[Leetcode] 169. Majority Element
Identifying the Problem 최빈값을 찾아라 단 최빈값은 배열 길이 절반 이상 있다. Input: nums = [3,2,3] Output: 3 Input: nums = [2,2,1,1,1,2,2] Output: 2 Organizing thoughts 바로 떠오르는 알고리즘이 ..
gold-goose.tistory.com
ascending이면 7번 연속으로 오른 것이므로 count가 7이고,
descending 이면 7번 연속으로 내린 것이므로 count가 -7이고,
mixed이면 -6~6 사이 값이 나온다.
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{
int a[8]; #음계 배열
int count = 0;
for(int i=0; i<8; i++) #음계 입력
cin >> a[i];
for(int i=1; i<8; i++)
{
if(a[i-1] < a[i])
count++;
else
count--;
}
if(count == 7)
cout << "ascending";
else if(count == -7)
cout << "descending";
else
cout << "mixed";
return 0;
}
반응형
'Algorithm' 카테고리의 다른 글
[백준] 4344. 평균은 넘겠지 (0) | 2021.11.09 |
---|---|
[Programmers] 스킬트리 (0) | 2021.11.07 |
[Leetcode] 455. Assign Cookies (0) | 2021.11.07 |
[Leetcode] 211. Design Add and Search Words Data Structure (0) | 2021.09.28 |
[Leetcode] 208. Implement Trie (Prefix Tree) (0) | 2021.09.26 |
댓글()