-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (84 loc) · 2.21 KB
/
main.cpp
File metadata and controls
96 lines (84 loc) · 2.21 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream f1("../exemplu1.in");
ifstream f2("../exemplu2.in");
ifstream f3("../exemplu3.in");
int matrice[1001][1001], stfin[1001], nrstfin, nrlitere;
char alfabet[101];
void initializare() {
for (int i = 0; i <= 1000; i++)
for (int j = 0; j <= 1000; j++)
matrice[i][j] = -1;
}
void citire1() {
int nrstari, nrfunctii, stare1, stare2, k = -1, cnt = -1, ok;
char cuv;
f3 >> nrstari >> nrfunctii >> nrstfin >> nrlitere;
for (int i = 0; i < nrfunctii; i++) {
f3 >> stare1 >> cuv >> stare2;
matrice[stare1][int(cuv)] = stare2;
ok = 0;
for (int j = 0; j <= cnt; j++) {
if (alfabet[j] == cuv)
ok = 1;
}
if (ok == 0)alfabet[++cnt] = char(cuv);
}
for (int i = 0; i < nrstfin; i++) {
f3 >> stfin[++k];
}
}
void stergelitera(char v[]) {
for (int i = 0; i < strlen(v); i++)
v[i] = v[i + 1];
}
int main() {
initializare();
citire1();
char cuvant[100001];
cin >> cuvant;
cin.get();
int stare, ok = 1, k = 0, okk;
int drum[10001];
stare = 0;
drum[0] = 0;
while (ok == 1 && strlen(cuvant) != 0) {
if (matrice[stare][(int) cuvant[0]] == -1)
ok = 0;
else {
stare = matrice[stare][(int) cuvant[0]];
stergelitera(cuvant);
drum[++k] = stare;
}
}
int posibilcuvvid = 0;
for(int i = 0; i < nrstfin; i++)
{
if( stfin[i] == 0)posibilcuvvid = 1;
}
if( cuvant[0] == '-' && ::strlen(cuvant) == 1)
{
if(posibilcuvvid == 1)cout<< "acceptat\n" << 0 << "->" <<0;
else cout << "neacceptat";
}
else{
if (ok == 0)
cout << "neacceptat";
else {
okk = 0;
for(int i = 0; i <nrstfin; i++)
if(stare == stfin[i]) okk = 1;
if(okk == 0)
cout << "neacceptat";
else
{
cout << "acceptat" << endl;
cout << drum[0];
for (int i = 1; i < k; i++)
cout << "->" << drum[i];}
}
}
return 0;
}