Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char **argv)
- {
- string s;
- cin >> s;
- stack<int> stck;
- vi cnt(256);
- for (int i = 0; i < s.size(); ++i) {
- if (s[i] == '(')
- stck.push(i);
- else if (s[i] == ')') {
- while (stck.empty() == false && stck.top() != '(')
- cnt[stck.top()]--, stck.pop();
- if (stck.empty() == false)
- stck.pop();
- } else {
- stck.push(s[i]);
- cnt[s[i]]++;
- if (cnt[s[i]] > 1) {
- cout << "No" << endl;
- return 0;
- }
- }
- }
- cout << "Yes" << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement