Aleksandr_Grigoryev

из автомата в код

Feb 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. //3X1^2*X2^1*X3^7-2X1^1*X2^2*X3^3+S(2X1)-4C(2X1);X1^2-2X1^1+3X1^0;S(2X1)-4C(2X1)//
  4. using namespace std;
  5. int main()
  6. {
  7.     char x;
  8.     bool b = true;
  9.     int q = 1, n;
  10.     ifstream f("Text.txt");
  11.     while (f.peek() != EOF && b == true)
  12.     {
  13.         f >> x;
  14.         cout << x;
  15.         switch (q)
  16.         {
  17.         case 1:
  18.             if (x >= '0' && x <= '9')
  19.             {
  20.                 q = 2;
  21.             }
  22.             else if (x == 'X')
  23.             {
  24.                 q = 3;
  25.             }
  26.             else if (x == 'S' || x == 'C')
  27.             {
  28.                 q = 6;
  29.             }
  30.             else b = false;
  31.             break;
  32.         case 2:
  33.             if (x == 'X')
  34.             {
  35.                 q = 3;
  36.             }
  37.             else if (x == 'S' || x == 'C')
  38.             {
  39.                 q = 6;
  40.             }
  41.             else b = false;
  42.             break;
  43.  
  44.         case 3:
  45.             if (x >= '0' && x <= '9')
  46.             {
  47.                 q = 4;
  48.             }
  49.             else b = false;
  50.             break;
  51.  
  52.         case 4:
  53.             if (x == '^')
  54.             {
  55.                 q = 5;
  56.             }
  57.             else b = false;
  58.             break;
  59.  
  60.  
  61.         case 5:
  62.             if (x >= '0' && x <= '9')
  63.             {
  64.                 q = 11;
  65.             }
  66.             else b = false;
  67.             break;
  68.  
  69.  
  70.         case 6:
  71.             if (x == '(')
  72.             {
  73.                 q = 7;
  74.             }
  75.             else b = false;
  76.             break;
  77.  
  78.  
  79.         case 7:
  80.             if (x >= '0' && x <= '9')
  81.             {
  82.                 q = 8;
  83.             }
  84.             else b = false;
  85.             break;
  86.  
  87.  
  88.         case 8:
  89.             if (x == 'X')
  90.             {
  91.                 q = 9;
  92.             }
  93.             else b = false;
  94.             break;
  95.  
  96.  
  97.         case 9:
  98.             if (x >= '0' && x <= '9')
  99.  
  100.             {
  101.                 q = 10;
  102.             }
  103.             else b = false;
  104.             break;
  105.  
  106.  
  107.         case 10:
  108.             if (x == ')')
  109.             {
  110.                 q = 11;
  111.             }
  112.             else b = false;
  113.             break;
  114.  
  115.  
  116.         case 11:
  117.             if (x == '+' || x == '-' || x == ';')
  118.             {
  119.                 q = 1;
  120.             }
  121.             else if (x == '*')
  122.             {
  123.                 q = 2;
  124.             }
  125.             else b = false;
  126.             break;
  127.         }
  128.  
  129.     }
  130.     cout << endl;
  131.     if (b )
  132.         cout << "all right!!";
  133.     else
  134.         cout << "error";
  135.     cout << endl;
  136.     system("pause");
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment