Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. // PAVEL_MELL.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include <iostream>  
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     setlocale(0, "");
  13.     int mark = 0,  i;
  14.     bool EO_line = false;
  15.     int difference = 0;
  16.     int mas[4][5] = {
  17.         // 0  1  a   b  \0
  18.         { 0, 1, 2, 3, -2},//0
  19.         { -1, 1, 2, -1, -2 },//1
  20.         { -1, -1, 2, 3, -2 }, //2
  21.         { -1, -1, -1, 3, -2 } };//3
  22.     string sequence;
  23.     cin >> sequence;
  24.     for (i = 0; i <= sequence.length(); i++) {
  25.  
  26.         switch (sequence[i]) {
  27.         case '0': mark = mas[mark][0];
  28.                   break;
  29.         case '1': mark = mas[mark][1];
  30.                   break;
  31.         case 'a': {
  32.             mark = mas[mark][2];
  33.             difference++;
  34.             break;
  35.         }
  36.         case 'b': {
  37.             mark = mas[mark][3];
  38.             difference--;
  39.             break;
  40.         }
  41.         case '\0': mark = mas[mark][4];
  42.                    break;
  43.         default: mark = -1;
  44.                  break;
  45.         }
  46.         if (mark == -2) {
  47.             EO_line = true;
  48.             break;
  49.         }
  50.         if (mark == -1) {
  51.             break;
  52.         }
  53.     }
  54.     if (difference > 0)
  55.         cout<< endl << "No, error in markition " << i + 1 << " = " << sequence[i] << endl;
  56.     else if (difference < 0)
  57.         cout << endl<< "No, error in markition " << i + 1 + (difference) << " = " << sequence[i + difference] << endl;
  58.     else if (not EO_line) {
  59.         cout << endl << "No, error in markition " << i + 1 << " = " << sequence[i] << endl;
  60.     }
  61.     else {
  62.         cout << "Yes" << endl;
  63.     }
  64.     //system("pause");
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement