본문 바로가기

백준/C++

[C++] 백준 2920번 - 음계

728x90

 

문제 2920번

https://www.acmicpc.net/problem/2920

 

숫자를 입력받을때마다 연주 순서를 판단하여 a와 d를 각각 증가시켜준다. 만약 a가 8이라면 1부터 8까지 차례대로 연주했다는 뜻이기 때문에 ascending을 출력한다. d가 8이라면 8부터 1까지 차례대로 연주했다는 것이기 때문에 descending을 출력한다. 둘 다 아니라면 mixed를 출력한다.

#include <iostream>
using namespace std;

int main() {
	int num[8];
	int a = 0, d = 0;
	for (int i = 0; i < 8; i++) {
		cin >> num[i];
		if (num[i] == i + 1) {
			a++;
		}
		else if (num[i] == 8 - i) {
			d++;
		}
	}
	if (a == 8) {
		cout << "ascending";
	}
	else if (d == 8) {
		cout << "descending";
	}
	else {
		cout << "mixed";
	}

	return 0;
}

 

728x90

'백준 > C++' 카테고리의 다른 글

[C++] 백준 2083번 - 럭비 클럽  (0) 2024.07.31
[C++] 백준 1076번 - 저항  (0) 2024.07.26
[C++] 백준 1676번 - 팩토리얼 0의 개수  (1) 2024.07.23
[C++] 백준 2163번 - 초콜릿 자르기  (1) 2024.07.22
[C++] 백준 1247번 - 부호  (1) 2024.07.20