-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask10a.cpp
More file actions
39 lines (38 loc) · 1.08 KB
/
task10a.cpp
File metadata and controls
39 lines (38 loc) · 1.08 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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
unordered_map<char, int> scores;
unordered_map<char, char> pairs;
pairs[')'] = '(';
pairs[']'] = '[';
pairs['}'] = '{';
pairs['>'] = '<';
scores[')'] = 3;
scores[']'] = 57;
scores['}'] = 1197;
scores['>'] = 25137;
string line;
int totalScore = 0;
char cur;
while (getline(cin, line)) {
stack<char> curStack;
for (int i = 0; i < line.size(); ++i) {
if (line[i] == '(' || line[i] == '[' || line[i] == '{' || line[i] == '<') {
curStack.push(line[i]);
} else {
if (curStack.empty()) {
totalScore += scores[line[i]];
break;
}
cur = curStack.top(); curStack.pop();
if (pairs[line[i]] != cur) {
totalScore += scores[line[i]];
break;
}
}
}
}
cout << totalScore;
return 0;
}