Stack

 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
#include <stdio.h>
#include <iostream>
#include <stack>
using namespace std;
int main() {
freopen("stack.in", "r", stdin);
freopen("stack.out", "w", stdout);
stack<int> S[10000];
int n;
char op;
int num, val;
scanf("%d\n", &n);
for(int i=0; i<n; i++) {
scanf("%c ",&op);
if(op=='+') {
scanf(" %d %d\n", &num, &val);
S[num].push(val);
}
else if(op=='-') {
scanf(" %d\n", &num);
if(!S[num].empty()) {
cout<<S[num].top()<<"\n";
S[num].pop();
}
}
}
return 0;
}