-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
71 lines (67 loc) · 1.31 KB
/
test.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,t,a,c,start,k,temp;
char b;
string str;
int v[100][256];// = {-1};
for(int i=0;i<100;i++){
for(int j=0;j<255;j++){
v[i][j] = -1;
}
}
cout<<"Enter no of states ---- ";
cin>>n;
cout<<"\n Enter no of transections = ";
cin>>t;
for(int i=0;i<t;i++){
cin>>a>>b>>c;
v[a][b] = c;
}
cout<<"start state = ";
cin>>start;
vector<int>accepted;
cout<<"No of accepted states = ";
cin>>k;
for(int i=0;i<k;i++){
cin>>temp;
accepted.push_back(temp);
}
int cases;
bool invalid = 0;
cout<<"Enter no of test cases = ";
cin>>cases;
int currentState = start;
while(cases--){
invalid =0;
currentState = start;
cout<<"Input String = ";
cin>>str;
for(int i= 0 ;i<str.length();i++){
if(v[currentState][str.at(i)] != -1){
currentState = v[currentState][str.at(i)];
//cout<<"i = "<<str.at(i)<<endl;
//cout<<"cur = "<<currentState<<endl;
}
else{
//cout<<"else"<<endl;
cout<<"Invalid"<<endl;
invalid = true;
break;
}
}
if(!invalid){
int flag =0;
for(int i=0;i<accepted.size();i++){
if(currentState == accepted[i]){
cout<<"valid"<<endl;
flag = 1;
break;
}
}
if(flag!=1)
cout<<"Invalid"<<endl;
}
}
return 0;
}