题解 | #有序序列判断#
有序序列判断
http://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int N = 0; scanf("%d", &N); int arr[40] = { 0 }; int i = 0; int sum1 = 0; int sum2 = 0; for (i = 0; i < N; i++) { scanf("%d", &arr[i]); } for (i = 1; i < N; i++) { if (arr[i] > arr[i - 1] || arr[i] == arr[i - 1]) { sum1++; } else if (arr[i] < arr[i - 1] || arr[i] == arr[i -1]) { sum2++; } } while (1) { if (sum1 == N - 1 || sum2 == N - 1) { printf("sorted\n"); break; } else { printf("unsorted\n"); break; } } return 0;
}