-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask10b.cpp
More file actions
54 lines (52 loc) · 1.38 KB
/
task10b.cpp
File metadata and controls
54 lines (52 loc) · 1.38 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
unordered_map<char, int> points;
points[')'] = 1;
points[']'] = 2;
points['}'] = 3;
points['>'] = 4;
unordered_map<char, char> pairs;
pairs['('] = ')';
pairs['['] = ']';
pairs['{'] = '}';
pairs['<'] = '>';
string line;
char cur;
ll curScore;
bool corrupted;
vector<ll> scores;
while (getline(cin, line)) {
stack<char> curStack;
corrupted = false;
for (auto &c : line) {
if (pairs.find(c) != pairs.end()) {
curStack.push(c);
} else {
if (curStack.empty()) {
break;
}
cur = curStack.top(); curStack.pop();
if (pairs[cur] != c) {
corrupted = true;
break;
}
}
}
curScore = 0;
while (!corrupted && !curStack.empty()) {
cur = curStack.top(); curStack.pop();
char close = pairs[cur];
curScore *= 5;
curScore += points[close];
}
if (curScore != 0) {
scores.push_back(curScore);
}
}
sort(scores.begin(), scores.end());
cout << scores[scores.size() / 2];
return 0;
}