-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.cpp
More file actions
50 lines (44 loc) · 881 Bytes
/
stack.cpp
File metadata and controls
50 lines (44 loc) · 881 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
// This code was created with the support of Sergo.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
using namespace std;
void file() {
freopen("stack.in","r", stdin);
freopen("stack.out","w", stdout);
}
// void ...
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
file();
int n;
cin >> n;
int ans[1000000 + 1];
int sz = 0, j = 0;
for(int i = 0; i < n; i++) {
char x;
cin >> x;
if(x == '+'){
int b;
cin >> b;
ans[j] = b;
j++;
sz++;
}
else {
cout << ans[j - 1] << endl;
ans[j] = 0;
j--;
sz--;
}
}
}