BOJ 문제풀이

백준 2920번 c++ 풀이

koreasunoo 2021. 8. 4. 22:44

 

안녕하세요 오늘은 쉬운 편에 속하는 문제를 풀어보겠습니다.

우선은 계속 8번동안 비교하면서 i번째 때 인풋이랑 i랑 다르면 as를 false로 지정해주고, i번째 반복때, 인풋이랑 9-i랑 다르면 de를 false로 지정해줍니다. 그리고 if문으로 출력합니다.

코드:

#include <bits/stdc++.h>
using namespace std;
int main(){
	bool as = true, de = true;
	for(int i = 1; i<=8; i++){
		int x;
		cin>>x;
		if(i!=x) as=false;
		if(x!=9-i) de = false;
	}
	if(as) cout<<"ascending";
	else if(de)	cout<<"descending";
	else cout<<"mixed";
}

'BOJ 문제풀이' 카테고리의 다른 글

백준 1920번 c++ 풀이  (0) 2021.08.04
백준 1259 c++ 풀이  (0) 2021.08.04
백준 2475번 c++ 풀이  (0) 2021.08.04
백준 2108번 c++ 풀이  (1) 2021.08.04
백준 10814 번 c++ 풀이  (0) 2021.08.03