Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //((a+b)*((-d)+(-e)))
- #include <string>
- using namespace std;
- int fun(string &str)
- {
- while(str.size())
- {
- cout<<str<<endl;
- if(str[0]=='(')
- {
- str=str.substr(1,str.size()-1);
- int k=fun(str);
- str=str.substr(k,str.size()-k);
- if(str[0]==')')
- continue;
- if(str[0]=='\0')
- return 0;
- if(str[0]!='*'&&str[0]!='+'&&str[0]!='-')
- {
- cout<<"Error"<<endl;
- exit(0);
- }
- }
- else
- {
- if(str[0]==')')
- {
- if(str[1]>=97&&str[1])
- {
- cout<<"Error"<<endl;
- exit(0);
- }
- if(str[1]!=')'&&(str.size()-1))
- str=str.substr(1,str.size()-1);
- str=str.substr(1,str.size()-1);
- continue;
- }
- if(str[0]=='-'&&str[1]>=97&&str[1]<=122&&str[2]==')')
- return 2;
- if(str[0]>=97&&str[0]<=122&&str[2]>=97&&str[2]<=122&&(str[1]>='*'||str[1]<='+'||str[1]>='-'))
- return 3;
- cout<<"Error"<<endl;
- exit(0);
- }
- }
- return 0;
- }
- int main()
- {
- string str;
- cin>>str;
- fun(str);
- cout<<"mission complete"<<endl;
- return 0;
- }
- //((a+b)*((-d)+(-e)))
- //(a+b)*((-d)+(-e)))
- //a+b)*((-d)+(-e)))
- //*((-d)+(-e)))
- //
- //
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement