fork download
  1. /* وَقُلْ رَبِّ زِدْنِي عِلْمًاً */
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <iomanip>
  7. #include <stack>
  8. #include <set>
  9. #include <queue>
  10. #include <deque>
  11. #include <vector>
  12. #include <fstream>
  13. #include <cctype>
  14. #include <utility>
  15.  
  16. #define ll long long
  17. #define ld long double
  18. #define sz(v) ((int)(v).size())
  19. #define all(v) ((v).begin()),((v).end())
  20. #define setp(n) cout << fixed << setprecision(n)
  21. #define O_o ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  22. #define yes cout << "yes\n"
  23. #define no cout << "no\n"
  24. #define fi(nn) for(ll i = 0; i < (nn); i++)
  25. #define fj(nn) for(ll j = 0; j < (nn); j++)
  26. #define fl(nn) for (ll i = nn - 1; i >= 0; i--)
  27. #define ffi(nn,mm) for(ll i = 0; i < (nn); i++)for(ll j = 0; j < (mm); j++)
  28. #define wt ll t;cin>>t;while(t--)
  29. #define null NULL
  30.  
  31. using namespace std;
  32. int main()
  33. {
  34. O_o
  35. string wo;
  36. cin >> wo;
  37. stack<char>s;
  38. fi(sz(wo)) {
  39.  
  40. if (wo[i] == '(' || wo[i] == '[' || wo[i] == '{') {
  41. s.push(wo[i]);
  42. }
  43. else {
  44. if (s.empty()) {
  45. no;
  46. return 0;
  47. }
  48. char ch = s.top();
  49. if (wo[i] == ')') {
  50. if (ch == '(') {
  51. s.pop();
  52. }
  53. else {
  54. no;
  55. return 0;
  56. }
  57. }
  58. else if (wo[i] == ']') {
  59. if (ch == '[') {
  60. s.pop();
  61. }
  62. else {
  63. no;
  64. return 0;
  65. }
  66. }
  67. else if (wo[i] == '}') {
  68. if (ch == '{') {
  69. s.pop();
  70. }
  71. else {
  72. no;
  73. return 0;
  74. }
  75. }
  76. }
  77. }
  78. if (s.empty()) {
  79. yes;
  80. }
  81. else {
  82. no;
  83. }
  84. return 0;
  85. }
Success #stdin #stdout 0.01s 5288KB
stdin
([)()]
stdout
no