题解 | 有序序列判断(最短的写法)

有序序列判断

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;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务