题解 | #有序序列判断#

有序序列判断

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

#include <stdio.h>
#include<string.h>
int main() {
int n;
scanf("%d",&n);
int a[n];
for(int i = 0;i<n;i++)
{
    scanf("%d",&a[i]);
}
int cou=0,dou =0,eou = 0;
for(int j = 0;j<n-1;j++)
{
    if(a[j]<a[j+1])
    cou++;
    if(a[j]>a[j+1])
    dou++;
    if(a[j]==a[j+1])
    eou++;
}
if(cou==n-1||dou==n-1||eou==n-1)
printf("sorted");
else
printf("unsorted");
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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