题解 | 有序序列判断(最短的写法)
有序序列判断
https://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> b = a;
reverse(b.begin(), b.end());
if (is_sorted(a.begin(), a.end()) || is_sorted(b.begin(), b.end())) puts("sorted");
else puts("unsorted");
return 0;
}