
c++判断整数数组元素是否已经按升序排序
【代码】c++判断整数数组元素是否已经按升序排序。
·
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
int main()
{
int x = 0;
vector<int>count;
int n;
while (cin >> n)
{
count.push_back(n);
}
int len = count.size();
for (int i = 0; i < len-1; i++)
{
// cout << count[i] << endl;
if (count[i] > count[i + 1])
{
x += 1;
}
}
if (x != 0)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
return 0;
}
更多推荐
所有评论(0)