fork download
  1. #include <iostream>
  2. #include <stack>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool Matched(const string& ps) {
  8.  
  9. const string opening("(");
  10. const string closing(")");
  11.  
  12. stack<char> ans;
  13. for(int i=0; i< ps.size(); ++i) {
  14. if(opening.find(ps[i]) != -1) ans.push(ps[i])
  15. else {
  16. if(ans.empty()) return false;
  17. if(opening.find(ans.top()) != closing.find(ps[i])) return false;
  18. ans.pop();
  19. }
  20. }
  21. return ans.empty();
  22. }
  23.  
  24. int main() {
  25. int testcase;
  26. string str;
  27.  
  28. cin >> testcase;
  29.  
  30. while(testcase--) {
  31.  
  32. cin >> str;
  33.  
  34. if(Match(str)) cout << "YES" << '\n';
  35. else cout << "NO" << '\n';
  36. }
  37.  
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
6
(())())
(((()())()
(()())((()))
((()()(()))(((())))()
()()()()(()()())()
(()((())()(
compilation info
prog.cpp: In function ‘bool Matched(const string&)’:
prog.cpp:15:3: error: expected ‘;’ before ‘else’
   else {
   ^~~~
prog.cpp: In function ‘int main()’:
prog.cpp:34:15: error: ‘Match’ was not declared in this scope
   if(Match(str)) cout << "YES" << '\n';
               ^
stdout
Standard output is empty