728x90
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
โญ ๋ด ์์ค ์ฝ๋
#include <stdio.h>
int main()
{
int arr[8];
int temp=0;
//ascending์ด ๋์ค๋ ์ผ์ด์ค
int asc[] = { 1,2,3,4,5,6,7,8 };
//descending์ด ๋์ค๋ ์ผ์ด์ค
int des[] = { 8,7,6,5,4,3,2,1 };
for (int a = 0; a < 8; a++) {
scanf("%d", &arr[a]);
}
//์
๋ ฅ ๋ฐ์ ๋ฌธ์์ด๊ณผ ascending ์ผ์ด์ค๋ฅผ ๋น๊ต
for (int b = 0; b < 8; b++) {
if (arr[b] == asc[b]) {
//ascending ์ผ์ด์ค์ ์ผ์นํ ๋๋ง๋ค ๊ฐ์ 1์ฉ ์ฆ๊ฐ
temp += 1;
}
//์ผ์นํ์ง ์๋ ๋ถ๋ถ์ด ๋์ค๋ฉด, ascending ์๋ ๊ฒ์ผ๋ก ํ๋จํ์ฌ ์ข
๋ฃ
else { break; }
}
//์
๋ ฅ ๋ฐ์ ๋ฌธ์์ด๊ณผ descending ์ผ์ด์ค๋ฅผ ๋น๊ต
for (int c = 0; c < 8; c++) {
if (arr[c] == des[c]) {
//descending ์ผ์ด์ค์ ์ผ์นํ ๋๋ง๋ค ๊ฐ์ 2์ฉ ์ฆ๊ฐ
temp += 2;
}
//์ผ์นํ์ง ์๋ ๋ถ๋ถ์ด ๋์ค๋ฉด, descending ์๋ ๊ฒ์ผ๋ก ํ๋จํ์ฌ ์ข
๋ฃ
else { break; }
}
//์ด ๊ฐ์ด 8์ด๋ฉด ๋ชจ๋ ascending ๊ฐ๊ณผ ์ผ์นํ ๊ฒ์ด๋ฏ๋ก ascending์ผ๋ก ํ๋จ
if (temp == 8) {
printf("ascending");
}
//์ด ๊ฐ์ด 16์ด๋ฉด ๋ชจ๋ descending ๊ฐ๊ณผ ์ผ์นํ ๊ฒ์ด๋ฏ๋ก descending์ผ๋ก ํ๋จ
else if (temp == 16) {
printf("descending");
}
//๊ทธ ์ธ์ ๊ฐ์ด ๋ค์ค๋ฉด mixed
else {
printf("mixed");
}
return 0;
}
๐ ๋ฌธ์ ํ์ด
- ascending์ด ๋์ค๋ ์ผ์ด์ค๋ {1,2,3,4,5,6,7,8}, descending์ด ๋์ค๋ ์ผ์ด์ค๋ {8,7,6,5,4,3,2,1} ๋ฐ์ ์กด์ฌํ์ง ์๋๋ค.
728x90