-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Card_Deck.cpp
More file actions
44 lines (36 loc) · 809 Bytes
/
B_Card_Deck.cpp
File metadata and controls
44 lines (36 loc) · 809 Bytes
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
40
41
42
43
44
#include <iostream>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n + 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
a[n] = n + 1;
stack<int> s;
int maxVal = a[0];
int last = 0;
for (int i = 0; i <= n; i++) {
if (a[i] > maxVal) {
for (int j = i - 1; j >= last; j--) {
s.push(a[j]);
}
last = i;
maxVal = a[i];
}
}
while (!s.empty()) {
cout << s.top() << " ";
s.pop();
}
cout << endl;
}
return 0;
}