题解 | #有序序列判断#

有序序列判断

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

#include <stdio.h>

void SortedPrint(const int n)
{
	int count1 = 0;
	int count2 = 0;
	int count3 = 0;
	int arr[100] = { 0 };
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (arr[i] <= arr[j])
			{
				count1++;
			}else if (arr[i] > arr[j])
			{
				count2++;
			}
			else
			{
				count3++;
			}
		}
	}
	//("%d %d %d", count1, count2, count3);
	if (count3 == 0 && count2 == 0 || count3 == 0 && count1 == 0)
	{
		printf("sorted\n");
	}
	else
	{
		printf("unsorted\n");
	}
}

int main()
{
	int n = 0;
	scanf("%d", &n);
	SortedPrint(n);
	return 0;
}

全部评论

相关推荐

听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务