fork download
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4. char a[100000];
  5.  
  6. bool match(char x, char y)
  7. {
  8. switch(x)
  9. {
  10. case '(': return (y == ')');
  11. case '[': return (y == ']');
  12. case '{': return (y == '}');
  13. }
  14.  
  15. }
  16.  
  17. bool check()
  18. {
  19. stack<char> b;
  20. for(int i = 0; a[i]; i++)
  21. {
  22. if(a[i] == '(' && a[i] == '[' && a[i] == '{')
  23. {
  24. b.push(a[i]);
  25. }
  26. else
  27. {
  28. if(b.empty())
  29. {
  30. return false;
  31. }
  32. else if(match(b.top(), a[i]))
  33. {
  34. return true;
  35. }
  36. else
  37. {
  38. return false;
  39. }
  40. }
  41. }
  42. }
  43.  
  44. int main() {
  45. cin >> a;
  46. if(check())
  47. {
  48. cout << "yes";
  49. }
  50. else
  51. {
  52. cout << "no";
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 4492KB
stdin
(([(}
stdout
no