ErnestGalbrun

Untitled

Dec 9th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. int main() {
  2.     vector<long long> scores;
  3.     unordered_map<char,char> M = {{'(', ')'}, {'[', ']'}, {'{', '}'}, {'<', '>'}};
  4.     unordered_map<char, int> P2 = {{'(', 1ll}, {'[', 2ll}, {'{', 3ll}, {'<', 4ll}};
  5.     for (std::string line; std::getline(std::cin, line);) {
  6.         stack<char> S;
  7.         for (auto c: line) {
  8.             if (M.contains(c)) {
  9.                 S.push(c);
  10.                 continue;
  11.             }
  12.             if(!S.empty() && c == M[S.top()]) {
  13.                 S.pop();
  14.                 continue;
  15.             }
  16.             break;
  17.         }
  18.         long long score = 0;
  19.         while (!S.empty()) {
  20.             score *=5ll;
  21.             score += P2[S.top()];
  22.             S.pop();
  23.         }
  24.         if (score) scores.push_back(score);
  25.     }
  26.  
  27.     sort(scores.begin(), scores.end());
  28.     cout << scores[scores.size()/2]<< endl;
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment