Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream> //((a+b)*((-d)+(-e)))
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int fun(string &str)
  8. {
  9.  
  10.     while(str.size())
  11.     {
  12.             cout<<str<<endl;
  13.  
  14.         if(str[0]=='(')
  15.         {
  16.             str=str.substr(1,str.size()-1);
  17.             int k=fun(str);
  18.             str=str.substr(k,str.size()-k);
  19.             if(str[0]==')')
  20.                 continue;
  21.             if(str[0]=='\0')
  22.                 return 0;
  23.             if((str[0]=='-'||str[0]=='*'||str[0]=='+')&&((str[1]>=97&&str[1]<=122)||str[1]=='('))
  24.             {
  25.                     str=str.substr(2,str.size()-2);
  26.                     continue;
  27.             }
  28.  
  29.             if(str[0]!='*'&&str[0]!='+'&&str[0]!='-')
  30.             {
  31.  
  32.  
  33.                 cout<<"Error1"<<endl;
  34.                 exit(0);
  35.             }
  36.    
  37.         }
  38.         else
  39.         {
  40.            
  41.             if(str[0]==')')
  42.             {
  43.                 if(str[1]>=97&&str[1])
  44.                 {
  45.                 cout<<"Error2"<<endl;
  46.                 exit(0);
  47.                 }
  48. /*
  49.                 if(str[1]!=')'&&(str.size()-1))
  50.                     str=str.substr(1,str.size()-1);
  51.                     */
  52.                 str=str.substr(1,str.size()-1);
  53.                 if((str[0]=='-'||str[0]=='*'||str[0]=='+')&&((str[1]>=97&&str[1]<=122)||str[1]=='('))
  54.             {
  55.                     str=str.substr(2,str.size()-2);
  56.                     continue;
  57.             }
  58.                 continue;
  59.             }
  60.             if(str[0]>=97&&str[0]<=122&&str[2]>=97&&str[2]<=122&&(str[1]>='*'||str[1]<='+'||str[1]>='-'))
  61.                 return 3;
  62.             cout<<"Error3"<<endl;
  63.             cout<<str<<endl;
  64.             exit(0);
  65.            
  66.    
  67.    
  68.    
  69.         }
  70.     }
  71.    
  72.        
  73.     return 0;
  74. }
  75.  
  76. int main()
  77. {
  78.     string str;
  79.     cin>>str;
  80.     fun(str);
  81.     cout<<"mission complete"<<endl;
  82.     return 0;
  83. }
  84.  
  85. //((a+b)*((-d)+(-e)))
  86. //(a+b)*((-d)+(-e)))
  87. //a+b)*((-d)+(-e)))
  88. //*((-d)+(-e)))
  89. //
  90. //
  91. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement