题解 | #有序序列判断#
有序序列判断
https://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e
#include <stdio.h> int main() { int a = 0; scanf("%d\n",&a); int arr1[100] = {0}; int flag = 0; for (int i = 0; i < a; i++) { scanf("%d ",&arr1[i]); } for (int i = 0; i < a - 2; i++) { if ((arr1[i] > arr1[i+1] && arr1[i+1]<arr1[i+2]) || (arr1[i] < arr1[i+1] && arr1[i+1] > arr1[i+2])) { // 乱序的两种方式 flag = 1; printf("unsorted\n"); break; } } if (flag == 0) { printf("sorted\n"); } return 0; }