include stdafx include string include iostream using namespace std boo

 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
bool analys(string word)
{
int i = 0;
int state = 'H';
while (word[i] != '\0')
{
switch (state)
{
case 'H':
{
if (word[i] == 'a') {
state = 'A'; break;
}
else return false;
}
case 'A':
{
if (word[i] == 'b') {
state = 'X'; break;
}
else return false;
}
case 'X':
{
if (word[i] == 'b') {
state = 'Y'; break;
}
else if (word[i] == 'c') {
state = 'Z'; break;
}
else return false;
}
case 'Y':
{
if (word[i] == 'b') break;
else return false;
}
case 'Z':
{
if (word[i] == 'c') break;
else return false;
}
}
i++;
}
if (state == 'Y' || state == 'Z') return true;
else return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "Russian");
string word;
cout << "Введите слово: ";
cin >> word;
if (analys(word))
cout << "Слово принадлежит грамматике.";
else
cout << "Слово не принадлежит грамматике.\n";
return 0;
}