PAT 1045 快速排序
程序员文章站
2022-07-15 14:02:05
...
#include <bits/stdc++.h>
#define TEST
using namespace std;
int main()
{
int n;
scanf("%d", &n);
static int input[100010];
static int output[100010];
static int max[100010];
int count = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &input[i]);
output[i] = input[i];
if (i == 0) max[i] = input[i];
else {
if(input[i] > max[i-1]) max[i] = input[i];
else max[i] = max[i - 1];
}
}
sort(output, output + n);
for (int i = 0; i < n; i++) {
if (output[i] != input[i] || output[i] != max[i])
output[i] = 0;
else count++;
}
printf("%d\n", count);
if (count == 0)
printf("\n");
else {
for (int i = 0; i < n; i++) {
if (output[i] != 0) {
printf("%d", output[i]);
if (count != 1) printf(" ");
count--;
}
}
}
#ifdef TEST
system("pause");
#endif
return 0;
}
上一篇: PAT1037 在霍格沃茨找零钱 (20 分)(C语言)
下一篇: 1037 在霍格沃茨找零钱