fork download
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s;
  7. cin >> s;
  8. stack<char> st;
  9. for (char c : s) {
  10. if (c == '(' || c == '{' || c == '[') {
  11. st.push(c);
  12. } else {
  13. if (st.empty() || (c == ')' && st.top() != '(') || (c == '}' && st.top() != '{') || (c == ']' && st.top() != '[')) {
  14. cout << "no";
  15. return 0;
  16. }
  17. st.pop();
  18. }
  19. }
  20. if (st.empty()) {
  21. cout << "yes";
  22. } else {
  23. cout << "no";
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 5304KB
stdin
()((
stdout
no