fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string s;
  4. int main(){
  5. while(true){
  6. getline(cin, s);
  7. if(s == ".") break;
  8. stack<char> stk;
  9. bool isImp = false;
  10. for(int i = 0; i < s.size(); i++){
  11. if(s[i] == '(' || s[i] == '[') stk.push(s[i]);
  12. else if(stk.size() && s[i] == ')'){
  13. if(stk.top() == '(') stk.pop();
  14. else isImp = true;
  15. } else if(stk.size() && s[i] == ']'){
  16. if(stk.top() == '[') stk.pop();
  17. else isImp = true;
  18. }
  19. }
  20. if(stk.size()) isImp = true;
  21.  
  22. if(isImp) cout << "no\n";
  23. else cout << "yes\n";
  24. }
  25. }
Success #stdin #stdout 0.01s 5316KB
stdin
So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
(.
.
stdout
yes
yes
no
no
no
yes
no