-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackOverflow.cpp
More file actions
75 lines (63 loc) · 1.37 KB
/
StackOverflow.cpp
File metadata and controls
75 lines (63 loc) · 1.37 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
using namespace std;
class stck{
int *ara;
int top;
public:
stck(){ top=0,ara=new int[10000]; };
void push(int x){ ara[top++]=x; };
void pop(){
if(top) top--;
};
void topf(){
if(!top) cout<<"Empty!\n";
else cout<<ara[top-1]<<'\n';
};
~stck(){ delete[] ara; }
friend void put(stck &i,stck &j);
};
void put(stck &i,stck &j){
for(int l=0;l<j.top;i.ara[i.top]=j.ara[l],i.top++,l++);
j.top=0;
};
int main()
{
stck *ara;
int T,N,Q;
char cmd[5];
int i,j;
cin>>T;
for(int l=0;l<T;l++)
{
cin>>N>>Q;
ara = new stck[N];
cout<<"Case "<<l+1<<":\n";
for(int l1=0;l1<Q;l1++)
{
cin>>cmd;
if(cmd[0]=='t'){
cin>>i;
i--;
ara[i].topf();
}
else if(cmd[1]=='o'){
cin>>i;
i--;
ara[i].pop();
}
else{
cin>>i>>j;
i--;
if(cmd[2]=='s'){
ara[i].push(j);
}
else{
j--;
put(ara[i],ara[j]);
}
}
}
delete[] ara;
}
return 0;
}