题解 | #有序序列判断#
有序序列判断
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; }