fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. int main() {
  7. stack <char> st;
  8. char c;
  9. while(cin>>c)
  10. {
  11. if (c=='(' || c=='[' || c=='{')
  12. {
  13. st.push(c);
  14. }
  15. else if (st.empty())
  16. {
  17. cout<<"no";
  18. return 0;
  19. }
  20. else
  21. {
  22. char c1=st.top();
  23. if (c1=='(' && c==')' || c1=='{' && c=='}' || c1=='[' && c==']')
  24. {
  25. st.pop();
  26. }
  27. else
  28. {
  29. cout<<"no";
  30. return 0;
  31. }
  32. }
  33. }
  34. if (st.empty())
  35. {
  36. cout<<"yes";
  37. }
  38. else
  39. {
  40. cout<<"no";
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 4252KB
stdin
Standard input is empty
stdout
yes