fork download
  1. #include<iostream>
  2. #include<stack>
  3. #include<string>
  4. using namespace std;
  5.  
  6. int main(){
  7. string input;
  8. getline(cin, input);
  9. stack<char> s;
  10. while(input != "."){
  11. for(char alpha : input){
  12. if(alpha == '['){
  13. s.push('[');
  14. }
  15.  
  16. else if(alpha == ']'){
  17. if(s.empty()){
  18. s.push(']');
  19. break;
  20. }
  21. else{
  22. if(s.top() == '['){
  23. s.pop();
  24. }
  25. }
  26. }
  27. else if(alpha == '('){
  28. s.push('(');
  29. }
  30. else if(alpha == ')'){
  31. if(s.empty()){
  32. s.push(')');
  33. break;
  34. }
  35. else{
  36. if(s.top() == '('){
  37. s.pop();
  38. }
  39. }
  40. }
  41. }
  42. if(s.empty()) {
  43. cout << "yes\n";
  44. }
  45. else{
  46. cout << "no\n";
  47. }
  48.  
  49. while(!s.empty()){
  50. s.pop();
  51. }
  52. getline(cin, input);
  53. }
  54. }
Success #stdin #stdout 0s 5384KB
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
yes