Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 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]!='-')
  24.             {
  25.  
  26.  
  27.                 cout<<"Error"<<endl;
  28.                 exit(0);
  29.             }
  30.    
  31.         }
  32.         else
  33.         {
  34.            
  35.             if(str[0]==')')
  36.             {
  37.                 if(str[1]>=97&&str[1])
  38.                 {
  39.                 cout<<"Error"<<endl;
  40.                 exit(0);
  41.                 }
  42.  
  43.                 if(str[1]!=')'&&(str.size()-1))
  44.                     str=str.substr(1,str.size()-1);
  45.                 str=str.substr(1,str.size()-1);
  46.                 continue;
  47.             }
  48.             if(str[0]=='-'&&str[1]>=97&&str[1]<=122&&str[2]==')')
  49.                 return 2;
  50.             if(str[0]>=97&&str[0]<=122&&str[2]>=97&&str[2]<=122&&(str[1]>='*'||str[1]<='+'||str[1]>='-'))
  51.                 return 3;
  52.             cout<<"Error"<<endl;
  53.             exit(0);
  54.            
  55.    
  56.    
  57.    
  58.         }
  59.     }
  60.    
  61.        
  62.     return 0;
  63. }
  64.  
  65. int main()
  66. {
  67.     string str;
  68.     cin>>str;
  69.     fun(str);
  70.     cout<<"mission complete"<<endl;
  71.     return 0;
  72. }
  73.  
  74. //((a+b)*((-d)+(-e)))
  75. //(a+b)*((-d)+(-e)))
  76. //a+b)*((-d)+(-e)))
  77. //*((-d)+(-e)))
  78. //
  79. //
  80. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement