-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcesor cu stiva.cpp
64 lines (55 loc) · 1.51 KB
/
Procesor cu stiva.cpp
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
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int n,val,rez=0;
vector<int>vec;
string in;
cin>>n;
for(int i=0;i<n;i++){
cin>>in;
if(in=="iload"){
cin>>val;
vec.push_back(val);
} if(in=="iadd"){
if(vec.size()>=2){
rez=vec[vec.size()-1]+vec[vec.size()-2];
vec.erase(vec.end()-1);vec.erase(vec.end()-1);
vec.push_back(rez);
}
else{
cout<<"Exception: line "<<i+1<<endl;
vec.clear();
break;
}
}
if(in=="imul"){
if(vec.size()>=2){
rez=vec[vec.size()-1]*vec[vec.size()-2];
vec.erase(vec.end()-1);
vec.erase(vec.end()-1);
vec.push_back(rez);
}else{
cout<<"Exception: line "<<i+1<<endl;
vec.clear();
break;
}
}
if(in=="dup"){
if(vec.size()>=1){
rez=vec[vec.size()-1];
vec.push_back(rez);
}else{cout<<"Exception: line "<<i+1<<endl;
vec.clear();
break;
}
}
}
if(vec.size()>=1){
cout<<vec.size()<<endl;
for(int i=vec.size()-1;i>=0;i--){
cout<<vec[i]<<endl;
}
}
}