#include <iostream>
#include <vector>
using namespace std;
//12:52
int main(void)
{
vector<int>v(8, 0);
for (int i = 0; i < v.size(); i++)
{
cin >> v[i];
}
bool check = false;
//오름차순
if (v[0] == 1)
{
for (int i = 0; i < v.size() - 1; i++)
{
if (v[i] > v[i + 1])
{
check = true;
break;
}
}
if (check == false)
{
cout << "ascending" ;
}
else
cout << "mixed" ;
}
//내림차순
else if (v[0] == 8)
{
for (int i = 0; i < v.size() - 1; i++)
{
if (v[i] < v[i + 1])
{
check = true;
break;
}
}
if (check == false)
{
cout << "descending" ;
}
else
cout << "mixed" ;
}
}
=> 효율성이 떨어진다.
어차피 들어오는 값 8개 중에서 2개를 비교하는 것이므로 내가 한 요 부분을 통일시키자.
#include <iostream>
#include <vector>
using namespace std;
//12:52
int main(void)
{
vector<int>v(8, 0);
for (int i = 0; i < v.size(); i++)
{
cin >> v[i];
}
bool bdescend = true;
bool bascend = true;
for (int i = 0; i < v.size() - 1; i++)
{
if (v[i] > v[i + 1])
{
bascend = false;
}
else if (v[i] < v[i + 1])
{
bdescend = false;
}
}
if (bascend)
cout << "ascending";
else if (bdescend)
cout << "descending";
else if (bascend == false && bdescend == false)
cout << "mixed";
}