728x90
숫자들이 오름차순인지, 내림차순인지, 섞여있는지 구별하는 문제입니다.
배열에 숫자를 받고 확인 한 후
switch문을 통해서 출력해 주었습니다.
#include <iostream>
#include <cstring>
using namespace std;
int arr[8];
int asc()
{
for (int i = 0; i < 7; ++i) {
if (arr[i] > arr[i + 1]) {
return 0;
}
}
return 1;
}
int dec()
{
for (int i = 0; i < 7; ++i) {
if (arr[i] < arr[i + 1]) {
return 0;
}
}
return 2;
}
int main(int argc, char *argv[])
{
int s;
for (int i = 0; i < 8; ++i) {
cin >> arr[i];
}
s = asc();
s += dec();
switch (s) {
case 0:
cout << "mixed" << endl;
break;
case 1:
cout << "ascending" << endl;
break;
case 2:
cout << "descending" << endl;
break;
}
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 15596번 정수 N개의 합 (0) | 2019.08.04 |
---|---|
[C++] 백준 8958번 OX퀴즈 (0) | 2019.08.04 |
[C++] 백준 10952번 A+B - 5 (0) | 2019.08.04 |
[C++] 백준 11022번 A+B - 8 (0) | 2019.08.04 |
[C++] 백준 11021번 A+B - 7 (0) | 2019.08.04 |