PAT A1069
考察整数每一位存储到数组
排序后重建整数
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N, max = -1;
scanf("%d", &N);
vector <int> a, b, ans;
a.resize(N);
b.resize(N);
for (int i = 0; i < N; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a.begin(), a.end());
for (int i = 0; i < N; i++) {
if (max < b[i]) {
max = b[i];
}
if (a[i] == b[i] && b[i] >= max) {
ans.push_back(a[i]);
}
}
int m = ans.size();
printf("%d\n", m);
for (int i = 0; i < m; i++) {
printf("%d", ans[i]);
if (i < m - 1)
printf(" ");
}
printf("\n");//少了换行符会有一个测试点格式错误
return 0;
}