-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path682.cpp
40 lines (39 loc) · 1.01 KB
/
682.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
class Solution {
public:
int calPoints(vector<string>& ops) {
int i=0;
stack<string>S;
int sum=0;
while(i!=ops.size()){
if(ops[i]=="+"){
string l=S.top();
S.pop();
string m=S.top();
S.push(l);
int qq=stoi(l);
int gg=stoi(m);
int rr=qq+gg;
S.push(to_string(rr));
sum+=stoi(S.top());
}
else if(ops[i]=="D"){
string v=S.top();
int yy=stoi(v);
int pp=2*yy;
string kk=to_string(pp);
S.push(kk);
sum+=stoi(S.top());
}
else if(ops[i]=="C"){
sum=sum-stoi(S.top());
S.pop();
}
else {
S.push(ops[i]);
sum+=stoi(S.top());
}
i++;
}
return sum;
}
};