-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem682.cpp
More file actions
33 lines (33 loc) · 800 Bytes
/
problem682.cpp
File metadata and controls
33 lines (33 loc) · 800 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
class Solution
{
public:
int calPoints(vector<string> &ops)
{
vector<int> record;
for (int i = 0; i < ops.size(); i++)
{
if (ops[i] == "D")
{
record.push_back(record.back() * 2);
}
else if (ops[i] == "C")
{
record.erase(record.begin() + (record.size() - 1));
}
else if (ops[i] == "+")
{
record.push_back(record[record.size() - 1] + record[record.size() - 2]);
}
else
{
record.push_back(stoi(ops[i]));
}
}
int sum = 0;
for (int i = 0; i < record.size(); i++)
{
sum += record[i];
}
return sum;
}
};