[백준] 2920 . 음계
Algorithm2021. 11. 7. 14:09
반응형
Boyer-Moore 알고리즘의 아이디어를 따와 풀었다.
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 |
댓글()