Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- vector<long long> scores;
- unordered_map<char,char> M = {{'(', ')'}, {'[', ']'}, {'{', '}'}, {'<', '>'}};
- unordered_map<char, int> P2 = {{'(', 1ll}, {'[', 2ll}, {'{', 3ll}, {'<', 4ll}};
- for (std::string line; std::getline(std::cin, line);) {
- stack<char> S;
- for (auto c: line) {
- if (M.contains(c)) {
- S.push(c);
- continue;
- }
- if(!S.empty() && c == M[S.top()]) {
- S.pop();
- continue;
- }
- break;
- }
- long long score = 0;
- while (!S.empty()) {
- score *=5ll;
- score += P2[S.top()];
- S.pop();
- }
- if (score) scores.push_back(score);
- }
- sort(scores.begin(), scores.end());
- cout << scores[scores.size()/2]<< endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment