Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.     setlocale(LC_CTYPE, "rus");
  10.     cout << "Введите логическое выражение" << endl;
  11.     string str;
  12.     getline(cin, str);
  13.  
  14.     {
  15.         for (int i = 0; i < str.length(); i++)
  16.         {
  17.  
  18.             if (str[i] >= 'A' && str[i] <= 'z' && str[i + 1] != 'o' && str[i + 1] != 'a' && str[i + 1] != 'n' && str[i + 1] != 'r')
  19.             {
  20.                 cout << str[i]<<setw(22) << " -идентификатор" << setw(40) << endl;
  21.             }
  22.  
  23.             if (str[i] == 'x' && str[i + 1] == 'o' && str[i + 2] == 'r')
  24.             {
  25.                 cout << "xor" << setw(22) << " -операция" << setw(40) << endl;
  26.                 i += 2;
  27.             }
  28.  
  29.             if (str[i] == 'o' && str[i + 1] == 'r' && str[i - 1] != 'x' && i != 0)
  30.             {
  31.                 cout << "or" << setw(22) << " -операция" << setw(40) << endl;
  32.                 i++;
  33.             }
  34.  
  35.             if (str[i] == 'n' && str[i + 1] == 'o' && str[i + 2] == 't')
  36.             {
  37.                 cout << "not" << setw(22) << " -операция" << setw(40) << endl;
  38.                 i += 2;
  39.             }
  40.  
  41.             if (str[i] == 'a' && str[i + 1] == 'n' && str[i + 2] == 'd')
  42.             {
  43.                 cout << "and" << setw(22) << " -операция" << setw(40) << endl;
  44.                 i += 2;
  45.             }
  46.  
  47.             if (str[i] == 'f' && str[i + 1] == 'a' && str[i + 2] == 'l' && str[i + 3] == 's' && str[i + 4] == 'e')
  48.             {
  49.                 cout << "false" << setw(22) << " -константанта" << setw(40) << endl;
  50.                 i += 4;
  51.             }
  52.  
  53.             if (str[i] == 't' && str[i + 1] == 'r' && str[i + 2] == 'u' && str[i + 3] == 'e')
  54.             {
  55.                 cout << "true" << setw(22) << " -константа" << setw(40) << endl;
  56.                 i += 3;
  57.             }
  58.  
  59.             if (str[i] == ':' && str[i + 1] == '=')
  60.             {
  61.                 cout  <<":=" << setw(22) << " -знак присваивания" << setw(40) << endl;
  62.                 i++;
  63.             }
  64.  
  65.             if (str[i] == '(' || str[i] == ')')
  66.             {
  67.                 cout << setw(22) << str[i] << setw(40) << " -скобка" << endl;
  68.                 i++;
  69.             }
  70.  
  71.             if (str[i] == ';')
  72.             {
  73.                 cout << setw(22) << str[i] << setw(40) << " -знак разделения" << endl;
  74.                 i++;
  75.             }
  76.  
  77.         }
  78.     }
  79.  
  80.     system("pause");
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement