题解 | #有序序列判断#

有序序列判断

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

#include <stdio.h>
int main()
{
    int n = 0;
    scanf("%d",&n);
    int i,j = 0;
    int count = 0;
    int sum = 0;
    int arr[100];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    
    for(i=0;i<n-1;i++)
    {
    	if(arr[i+1]>arr[i] || arr[j+1]==arr[j])
    	{
    		++count;
		}
		else if(arr[i+1]<arr[i])
		{
			++sum;
		}
	}
	if(sum>0 && count>0)
	{
		printf("unsorted\n");
	}
	else if(count==n-1 || sum==n-1)
	{
		printf("sorted\n");
	}
	//printf("%d %d",count,sum);--测试代码所用,观察count,sum和n的关系
    return 0;
}

全部评论

相关推荐

合不合适,我自己说了才算
码农索隆:hr:“真执着啊,来我公司当法人吧”
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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