include iostream include stdio using namespace std bool analysator cha

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <stdio.h>
using namespace std;
bool analysator()
{
char in = getchar();
char state = 'H';
while (in != '\n')
{
switch (state)
{
case 'H':
if (in == '0') state = 'X';
else if (in == '1') state = 'C';
else return 0;
break;
case 'X':
if (in == '1') state = 'Y';
else return 0;
break;
case 'Y':
if (in == '0') state = 'X';
else if (in == '1') ;
else return 0;
break;
case 'C':
if (in == '0') state = 'X';
else return 0;
break;
}
in = getchar();
}
if (state == 'C' || state == 'Y') return 1;
else return 0;
}
int main()
{
setlocale(LC_ALL, "Russian");
cout << "Введите цепочку для проверки: ";
if (analysator()) cout << "\nЦепочка принадлежит грамматике\n";
else cout << "\nЦепочка не принадлежит грамматике\n";
return 1;
}