题解 | #有序序列判断#
有序序列判断
https://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e
int main() { int arr[50] = { 0 }; int n = 0; scanf("%d", &n); int i = 0; int flag = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i = 0; i < n - 1; i++) { if (arr[i] >= arr[i + 1]) flag++; else flag--; } if ((flag == n - 1) || (flag == 1 - n)) printf("sorted\n"); else printf("unsorted\n"); return 0; }