Advertisement
zakharovafm

автомат Г

Apr 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.     ifstream in("input.txt");
  9.     ofstream out("out.txt");
  10.     char s, y;
  11.     out << "New string: " << endl;
  12.     int q = 1, count = 1;
  13.     bool p1 = false;
  14.     bool p2 = false;
  15.     bool p3 = false;
  16.     while ((in >> s) && (q != 5))
  17.     {
  18.         switch (q)
  19.         {
  20.         case 1:
  21.             if (s == 'a') {
  22.                 out << 'm';
  23.                 q = 2;
  24.                 y = 'm';
  25.             }  
  26.             else if (s == 'b') {
  27.                 out << 'p';
  28.                 q = 2;
  29.                 y = 'p';
  30.             }
  31.             else q = 5;
  32.             break;
  33.         case 2:
  34.             if (s == 'a') {
  35.                 out << 'm';
  36.                 q = 3;
  37.                 y = 'm';
  38.             }
  39.             else if (s == 'b') {
  40.                 out << 's';
  41.                 q = 3;
  42.                 y = 's';
  43.             }
  44.             else q = 5;
  45.                 break;
  46.         case 3:
  47.             if (s == 'a') {
  48.                 out << 'v';
  49.                 q = 4;
  50.                 y = 'v';
  51.             }
  52.             else if (s == 'b') {
  53.                 out << 'r';
  54.                 q = 1;
  55.                 y = 'r';
  56.             }
  57.             else    q = 5;
  58.             break;
  59.         case 4:
  60.             if (s == 'a') {
  61.                 out << 'p';
  62.                 q = 4;
  63.                 y = 'p';
  64.             }
  65.             else if (s == 'b') {
  66.                 out << 's';
  67.                 q = 3;
  68.                 y = 's';
  69.             }
  70.             else q = 5;
  71.                 break;
  72.         }
  73.         count++;
  74.         if (count == 10 && y == 'm')
  75.             p1 = true;
  76.         if (count == 20 && y == 'm')
  77.             p2 = true;
  78.         if (count == 30 && y == 'm')
  79.             p3 = true;
  80.     }
  81.     if (p1) cout << "y1 at 10th" << endl;
  82.     else cout << "not y1 at 10th" << endl;
  83.     if (p2) cout << "y1 at 20th" << endl;
  84.     else cout << "not y1 at 20th" << endl;
  85.     if (p3) cout << "y1 at 30th" << endl;
  86.     else cout << "not y1 at 30th" << endl;
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement