Aleksandr_Grigoryev

ДЗ №1 (кол-во слов и чисел в тексте)

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