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
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
bool analys(string word)
{
int i = 0;
int sost = 'H';
if (word[0] != '0') return false;
while (1)
{
switch (sost)
{
case 'H':
{
if (word[i] == '0') {
sost = 'B'; break;
}
else return false;
}
case 'B':
{
if (word[i] == '1') {
sost = 'X'; break;
}
else return false;
}
case 'X':
{
if (word[i] == '0') {
sost = 'B'; break;
}
else if (word[i] == '\0') {
return true;
}
}
}
i++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "Russian");
string word;
cout << "Введите слово: ";
cin >> word;
if (analys(word))
cout << "Слово принадлежит грамматике.";
else
cout << "Слово не принадлежит грамматике.\n";
return 0;
}