-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1045.cpp
39 lines (38 loc) · 865 Bytes
/
1045.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int i(0), max(0), maxi(0);
int Nums[100000] = {0};
int n;
for (; i<N; ++i) {
scanf("%d",&n);
if (n > max) {// 如果比现在最大值大 一定可以进来
Nums[maxi++] = n;
max = n;
}
else {// 不能成为主元 但却可以淘汰其他主元
int j = 0;
for (j=maxi-1; j>=0; --j) {
if (Nums[j] > n) {
Nums[j] = 0;
maxi--;
}
else {
maxi = j+1;
break;
}
}
}
}
cout << maxi << endl;
if (maxi)
for (i=0; i<maxi; ++i) {
if(!i) cout << Nums[i];
else cout << " " << Nums[i];
}
cout << endl;
return 0;
}