Advertisement
pb_jiang

ABC283D RE

Dec 26th, 2022 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. int main(int argc, char **argv)
  2. {
  3.     string s;
  4.     cin >> s;
  5.     stack<int> stck;
  6.     vi cnt(256);
  7.     for (int i = 0; i < s.size(); ++i) {
  8.         if (s[i] == '(')
  9.             stck.push(i);
  10.         else if (s[i] == ')') {
  11.             while (stck.empty() == false && stck.top() != '(')
  12.                 cnt[stck.top()]--, stck.pop();
  13.             if (stck.empty() == false)
  14.                 stck.pop();
  15.         } else {
  16.             stck.push(s[i]);
  17.             cnt[s[i]]++;
  18.             if (cnt[s[i]] > 1) {
  19.                 cout << "No" << endl;
  20.                 return 0;
  21.             }
  22.         }
  23.     }
  24.     cout << "Yes" << endl;
  25.     return 0;
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement