Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //((a+b)*((-d)+(-e)))
- #include <fstream>
- #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]=='+')&&((str[1]>=97&&str[1]<=122)||str[1]=='('))
- {
- str=str.substr(2,str.size()-2);
- continue;
- }
- if(str[0]!='*'&&str[0]!='+'&&str[0]!='-')
- {
- cout<<"Error1"<<endl;
- exit(0);
- }
- }
- else
- {
- if(str[0]==')')
- {
- if(str[1]>=97&&str[1])
- {
- cout<<"Error2"<<endl;
- exit(0);
- }
- /*
- if(str[1]!=')'&&(str.size()-1))
- str=str.substr(1,str.size()-1);
- */
- str=str.substr(1,str.size()-1);
- if((str[0]=='-'||str[0]=='*'||str[0]=='+')&&((str[1]>=97&&str[1]<=122)||str[1]=='('))
- {
- str=str.substr(2,str.size()-2);
- continue;
- }
- continue;
- }
- if(str[0]>=97&&str[0]<=122&&str[2]>=97&&str[2]<=122&&(str[1]>='*'||str[1]<='+'||str[1]>='-'))
- return 3;
- cout<<"Error3"<<endl;
- cout<<str<<endl;
- exit(0);
- }
- }
- return 0;
- }
- int main()
- {
- string str, command;
- cout << R"(Would u like to get input from "input.txt"? Y/N)" << endl;
- cin>>str;
- if (str[0] == 'Y') {
- cout << R"(Searching for it...)" << endl;
- ifstream input ("input.txt", ifstream::in);
- if (input.fail()) {
- cout << "File is not certain." << endl;
- return 0;
- }
- getline(input, command);
- } else if (str[0] == 'N') {
- cout << R"(Then type the string!)" << endl;
- cin>>command;
- } else {
- cout << "Try once again..." << endl;
- return 0;
- }
- cout<<command<<endl;
- fun(command);
- cout<<"mission complete"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement