fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stack>
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9. stack<int> s;
  10. int i,a,b,k;
  11. char c;
  12.  
  13. while(1){
  14.  
  15. a=0,b=0,k=0;
  16. char str[101];
  17. cin.getline(str,101);
  18.  
  19. if(!strcmp(str,"."))
  20. return 0;
  21.  
  22. for(i=0;str[i]!=NULL;i++){
  23.  
  24. if( str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']' )
  25. s.push(str[i]);
  26. }
  27.  
  28.  
  29. while(!s.empty()){
  30.  
  31. if(s.top()==']')
  32. a++;
  33.  
  34. else if(s.top()==')')
  35. b++;
  36.  
  37. else if(s.top()=='['){
  38.  
  39. a--;
  40.  
  41. if(c==')')
  42. k=1;
  43. if(a<0)
  44. k=1;
  45. }
  46. else{
  47.  
  48. b--;
  49.  
  50. if(c==']')
  51. k=1;
  52. if(b<0)
  53. k=1;
  54. }
  55.  
  56. c=s.top();
  57. s.pop();
  58. }
  59. if(k==1 || !(a==0 && b==0))
  60. printf("no\n");
  61. else
  62. printf("yes\n");
  63.  
  64.  
  65. }
  66.  
  67. }
Success #stdin #stdout 0s 4400KB
stdin
[[(([])])]
.
stdout
yes