Advertisement
Radio_jazz

Количество слов и цифр (Автомат)

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