문제 출처 :
https://www.acmicpc.net/problem/2920
2920번: 음계
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8
www.acmicpc.net

저는 이 문제를 loop를 만들어서 ascending인지 descending인지 먼저 파악을 한 후 둘다 아니라면 믹스로 판단하게끔 하였습니다.
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
// s is Scale
int s ;
// a is ascending and d is descending
bool a = true, d = true ;
for(int i = 1; i <= 8; i++){
cin >> s ;
if(s==i && a){
d = false ;
}
else if(s==9-i && d){
a = false ;
}
else{
a = false ;
d = false ;
}
}
if(a)
printf("ascending") ;
else if(d)
printf("descending") ;
else
printf("mixed") ;
return 0 ;
}
다음과 같이 맞출 수 있었습니다.

https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P2920_Scale.cpp
GitHub - gurcks8989/CodingTest: BackJoon_study_with_c++
BackJoon_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수, 조언 언제나 환영입니다.
문제 출처 :
https://www.acmicpc.net/problem/2920
2920번: 음계
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8
www.acmicpc.net

저는 이 문제를 loop를 만들어서 ascending인지 descending인지 먼저 파악을 한 후 둘다 아니라면 믹스로 판단하게끔 하였습니다.
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
// s is Scale
int s ;
// a is ascending and d is descending
bool a = true, d = true ;
for(int i = 1; i <= 8; i++){
cin >> s ;
if(s==i && a){
d = false ;
}
else if(s==9-i && d){
a = false ;
}
else{
a = false ;
d = false ;
}
}
if(a)
printf("ascending") ;
else if(d)
printf("descending") ;
else
printf("mixed") ;
return 0 ;
}
다음과 같이 맞출 수 있었습니다.

https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P2920_Scale.cpp
GitHub - gurcks8989/CodingTest: BackJoon_study_with_c++
BackJoon_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수, 조언 언제나 환영입니다.