Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

지극히 개인적인 개발블로그

백준 알고리즘 2920: 음계(C++) 본문

알고리즘

백준 알고리즘 2920: 음계(C++)

코드분쇄기 2019. 9. 19. 13:17

#include <iostream>
using namespace std;

int main()
{
	int arr[8];
	int asc = 0;
	int dsc = 0;
	for (int i = 0; i < 8; i++)
	{
		cin >> arr[i];

		if (arr[i] == i + 1)
			asc += 1;
		else if (arr[i] == 8 - i)
			dsc += 1;
	}
	if (asc == 8)
		cout << "ascending";
	else if (dsc == 8)
		cout << "descending";
	else
		cout << "mixed";
	return 0;
}

 

처음엔 asc와 dsc를 bool값으로 줘서 true, false플래그를 세우려 했으나

 

if분기가 너무 복잡해지는 문제로 정수로 판단했습니다. 결과적으로는 그게 더 코드가 간결하네요.