문제 |
2920번: 음계
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8
www.acmicpc.net
코드 |
#include <iostream>
#include <array>
using namespace std;
int main() {
array<int, 8> arr;
for (int &i : arr) {
cin >> i;
}
array<int, 8> ascend = {1, 2, 3, 4, 5, 6, 7, 8};
array<int, 8> descend = {8, 7, 6, 5, 4, 3, 2, 1};
string res;
if (arr == ascend) res = "ascending";
else if (arr == descend) res = "descending";
else res = "mixed";
cout << res;
return 0;
}
설명 |
== 으로 두 배열이 같은지 비교하려면 C 스타일의 배열이 아닌
std::array 클래스를 사용하여야 한다.
'PS > BOJ' 카테고리의 다른 글
[C++] BOJ (백준) 8958 : OX퀴즈 (0) | 2022.09.08 |
---|---|
[C++] BOJ (백준) 3052 : 나머지 (0) | 2022.09.07 |
[C++] BOJ (백준) 2908 : 상수 (0) | 2022.09.06 |
[C++] BOJ (백준) 2884 : 알람 시계 (0) | 2022.09.06 |
[C++] BOJ (백준) 2742 : 기찍 N (0) | 2022.09.06 |