题解 | 有序序列判断

有序序列判断

https://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e

#include <iostream>
using namespace std;

int main() {
    bool flag1=1,flag2=1;
    int t;cin>>t;
    int x,y;
    cin>>x;
    //从小到大
    //从大到小
    for(int i=1;i<=t-1;i++)
    {
        cin>>y;
        if(y<x)
        {
            flag1=0;
        }
        if(y>x)
        {
            flag2=0;
        }
        x=y;
    }
    //1,0;0,1;11/00;
    if(!flag1&&!flag2)
    {
        cout<<"unsorted";
        return 0;
    }
    cout<<"sorted";
}
// 64 位输出请用 printf("%lld")

尤其注意考虑111这种数字相等的情况!

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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