Aleksandr_Grigoryev

ДЗ №1 (вещественная запись)

Feb 14th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int q = 1;
  9.     char x;
  10.     ifstream f("Text2.txt");
  11.     while ((f.peek() != EOF) && q)
  12.     {
  13.         f >> x;
  14.         switch (q)
  15.         {
  16.         case 1: {
  17.             if ((x == '+') || (x == '-'))
  18.                 q = 2;
  19.             else
  20.                 q = 0;
  21.    
  22.             break;
  23.         }
  24.         case 2: {
  25.             if (!(x >= '0' && x <= '9'))
  26.             {
  27.                 if (x == '.')
  28.                     q = 3;
  29.                 else
  30.                     q = 0;
  31.             }
  32.        
  33.             break;
  34.         }
  35.         case 3: {
  36.             if (!(x >= '0' && x <= '9'))
  37.             {
  38.                 if (x == 'E' || x == 'e')
  39.                     q = 4;
  40.                 else
  41.                     q = 0;
  42.             }
  43.    
  44.             break;
  45.         }
  46.         case 4: {
  47.             if ((x == '+') || (x == '-'))
  48.                 q = 5;
  49.             else
  50.                 q = 0;
  51.            
  52.             break;
  53.         }
  54.         case 5: {
  55.             if (!(x >= '0' && x <= '9'))
  56.                 q = 0;
  57.             else q = 6;
  58.    
  59.             break;
  60.         }
  61.         case 6: {
  62.             if (!(x >= '0' && x <= '9'))
  63.                 q = 0;
  64.    
  65.             break;
  66.         }
  67.         }
  68.     }
  69.     if (q == 6)
  70.         cout << "YEeES" << endl;
  71.     else
  72.         cout << "NO" << endl;
  73.     system("pause");
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment