神奇的输入输出,tm还必须是最外层套一个while
#include<stdio.h> int main(int argc, char const *argv[]) { int num = 0, sflag = 0, ntmp = 0, stmp = 0; while (scanf("%d", &num) != EOF) { int arrays[num]; for (int i = 0; i < num; i++) { ntmp = 0; scanf("%d", &ntmp); arrays[i] = ntmp; } scanf("%d", &sflag); //冒泡排序 for (int i = 0; i < num; i++) { for (int j = i+1; j < num; j++) { if (sflag == 1) { //降序 if (arrays[i] < arrays[j]) { stmp = 0; stmp = arrays[i]; arrays[i] = arrays[j]; arrays[j] = stmp; } } else { //升序 if (arrays[i] > arrays[j]) { stmp = 0; stmp = arrays[i]; arrays[i] = arrays[j]; arrays[j] = stmp; } } } } //打印数组 for (int i = 0; i < num; i++) { printf("%d ", arrays[i]); } printf("\n"); } return 0; }