문제
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다.
1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다.
연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.
입력
첫째 줄에 8개 숫자가 주어진다. 이 숫자는 문제 설명에서 설명한 음이며, 1부터 8까지 숫자가 한 번씩 등장한다.
출력
첫째 줄에 ascending, descending, mixed 중 하나를 출력한다.
예제 입력 1
1 2 3 4 5 6 7 8 |
예제 출력 1
ascending |
예제 입력 2
8 7 6 5 4 3 2 1 |
예제 출력 2
descending |
예제 입력 3
8 1 7 2 6 3 5 4 |
예제 출력 3
mixed |
더보기
Solution
#include<stdio.h>
#include<stdbool.h>
int main(void)
{
bool ascending=true, descending=true;
int order[8];
for(int i=0;i<8;i++)
scanf("%d", &order[i]);
for(int i=1;i<8;i++)
if(order[i]>order[i-1])
descending=false;
else
ascending=false;
if(ascending)
printf("ascending\n");
else if(descending)
printf("descending\n");
else
printf("mixed\n");
return 0;
}
728x90
'백준 알고리즘' 카테고리의 다른 글
<백준 알고리즘> 15680번: 연세대학교 (0) | 2020.07.17 |
---|---|
<백준 알고리즘> 1065번: 한수 (0) | 2020.07.16 |
<백준 알고리즘> 2609번: 최대공약수와 최소공배수 (0) | 2020.07.16 |
<백준 알고리즘> 2445번: 별 찍기 - 8 (0) | 2020.07.16 |
<백준 알고리즘> 2444번: 별 찍기 - 7 (0) | 2020.07.16 |