include iostream include fstream include string using namespace std co

 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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int LITERA = 256, N = 40;
int main()
{
ifstream in_t ("tokens.txt");
int automat [N][LITERA] = {0};
int b[N] = {-1};
int n_status = 1;
int n_string = 0;
for (char c = '0'; c <= '9'; c++)
automat[0][c] = automat[n_status][c] = n_status;
n_status++;
for (char c = 'A'; c <= 'Z'; c++)
automat[0][c] = automat[n_status][c] = n_status;
for (char c = 'a'; c <= 'z'; c++)
automat[0][c] = automat[n_status][c] = n_status;
for (char c = '0'; c <= '9'; c++)
automat[n_status][c] = n_status;
n_status++;
while (in_t.peek() != EOF)
{
string temp;
getline(in_t, temp);
int status = 0;
for (int i = 0; i < temp.size(); i++)
{
if (!automat[status][temp[i]] || automat[status][temp[i]] == 2)
{
automat[status][temp[i]] = n_status;
status = n_status++;
}
else status = automat[status][temp[i]];
}
b[status] = n_string++;
}
ifstream in ("input.txt");
int status;
while(in.peek() != EOF)
{
status = 0;
string temp;
getline(in, temp);
for (int i = 0; i < temp.size(); i++)
{
status = automat[status][temp[i]];
}
cout << b[status] << endl;
}
return 0;
}