1101. Quick Sort

来源:互联网 发布:海外网络推广 编辑:程序博客网 时间:2024/05/20 12:48

崩溃啊,第三个测试点格式错误,百度了一下简直拍桌子,没数据的时候要输出两个回车……= =考试的时候遇到这种情况我可能要画圈圈了……

控诉一下win10,提交看结果的时候你就断网是不是跟爸爸过不去??

#include <stdio.h>#include <stdlib.h>/*快速排序一趟使主元落在最终位置,因此就是排序好的*/int main(){int n,i,cnt;scanf("%d", &n);long *data = (long*)malloc(sizeof(long)*n);int *IsPivot = (int*)malloc(sizeof(int)*n);long LeftMax=0, RightMin;cnt = n;for (i = 0; i < n; i++) {scanf("%d",&data[i]);if (LeftMax > data[i]) {/*与左边的最大值比较*/IsPivot[i] = 0;cnt--;}else {IsPivot[i] = 1; LeftMax = data[i];}}RightMin = data[n - 1];for (i = n - 1; i >= 0; i--) if (RightMin < data[i]) {if (IsPivot[i])cnt--;IsPivot[i] = 0;}elseRightMin = data[i];printf("%d\n",cnt);for (i = 0; cnt; i++) {if (IsPivot[i]) {printf("%ld", data[i]);cnt--;if (cnt)printf(" ");}}printf("\n");return 0;}

0 0