1->8을 차례대로 오름차순으로 올라가면 ascending을
8->1로 차례대로 내림차순으로 내려가면 descending을
둘 다 아니면 mixed을 출력하는 문제입니다.
간단하게 각각의 오름차순 내림차순 배열과 비교하여 같은 배열일 때 해당하는 답을 출력하도록 했습니다.
#include<iostream>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int result_flag = 0;
int flag = 0;
int prev = 0;
int arr[8] = {};
int ascend[8] = { 1,2,3,4,5,6,7,8 };
int descend[8] = { 8,7,6,5,4,3,2,1 };
for (int i = 0;i < 8;i++)
{
cin >> arr[i];
}
for (int i = 0;i < 8;i++)
{
if (arr[i] == ascend[i])
flag++;
}
if (flag == 8)
{
cout << "ascending";
result_flag = 1;
}
flag = 0;
for (int i = 0;i < 8;i++)
{
if (arr[i] == descend[i])
flag++;
}
if (flag == 8)
{
cout << "descending";
result_flag = 1;
}
if (result_flag == 0)
cout << "mixed";
return 0;
}