题解 | #有序序列判断#
有序序列判断
http://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e
#include<stdio.h>
int main()
{
int n = 0;
int arr[20] = { 0 };
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
int m = 0;
if (arr[0] >= arr[1])
{
for (int x = 0; x < n - 1; x++)
{
if (arr[x] >= arr[x + 1])
m++;
//continue;
else
break;
}
}
if (arr[0] < arr[1])
{
for (int x = 0; x < n - 1; x++)
{
if (arr[x] < arr[x + 1])
m++;
//continue;
else
break;
}
}
if (m == n - 1)
printf("sorted");
else
printf("unsorted");
return 0;
}
int main()
{
int n = 0;
int arr[20] = { 0 };
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
int m = 0;
if (arr[0] >= arr[1])
{
for (int x = 0; x < n - 1; x++)
{
if (arr[x] >= arr[x + 1])
m++;
//continue;
else
break;
}
}
if (arr[0] < arr[1])
{
for (int x = 0; x < n - 1; x++)
{
if (arr[x] < arr[x + 1])
m++;
//continue;
else
break;
}
}
if (m == n - 1)
printf("sorted");
else
printf("unsorted");
return 0;
}
顺丰集团工作强度 434人发布