Advertisement
Guest User

Untitled

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