-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Ultimate_Army.cpp
More file actions
54 lines (43 loc) · 940 Bytes
/
A_Ultimate_Army.cpp
File metadata and controls
54 lines (43 loc) · 940 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
45
46
47
48
49
50
51
52
53
54
#include "bits/stdc++.h"
using namespace std;
using ll =long long;
#define pb push_back
#define mp make_pair
void solve() {
int n;
cin >> n;
string s;
cin >> s;
vector<ll> v(n + 1, 0);
stack<ll> st;
int num=0;
for (ll i = 0; i < s.size();i++ ) {
if (isdigit(s[i])) {
num=10*num+(s[i]-'0');
}
else if (s[i] == ')') {
if (!st.empty()) {
v[num] = st.top();
}
if(num==0) st.pop();
num=0;
}else{
if(!st.empty()) v[num]=st.top();
if(num!=0)st.push(num);
num=0;
}
}
for (ll i = 1; i <= n; i++) {
cout << v[i] << " ";
}
cout << endl;
}
int main()
{
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
}