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
|
#include<iostream>
using namespace std;
class state{
public:
int num;
state* start;
state* q1;
state* q2;
state* q3;
state* q4;
state* q5;
state* now;
void getTheInput(char);
bool equal(state*,state*);
void get(state*,state*);
};
void state::get(state *a,state*b){
a=b;
}
bool state::equal (state *a,state* b){
return a==b;
}
void state::getTheInput(char a)
{
if(a=='a' || a=='b')
{
if(equal(now,start) && a=='a'){
cout<<"1";
get(now,q1);
}
if(equal(now,start) && a=='b')
get(now,start);
if(equal(now,q1) && a=='a')
cout<<"1";
get(now,q1);
if(equal(now,q1) && a=='b')
get(now,q2);
if(equal(now,q2) && a=='a')
get(now,q3);
if(equal(now,q2) && a=='b')
get(now,start);
if(equal(now,q3) && a=='a')
get(now,q1);
if(equal(now,q3) && a=='b')
get(now,q4);
if(equal(now,q4) && a=='a')
get(now,q3);
if(equal(now,q4)&& a=='b'){
get(now,q5);
cout<<"Got it!!!";
}
if(equal(now,q5) && a=='a')
get(now,q1);
if(equal(now,q5) && a=='b')
get(now,start);
}
else {
cout<<"Wrong input!! just 'a' or 'b'";
}
}
int main()
{
char a;
state *test=new state();
test->now=test->start;
for(;;)
{
cin>>a;
test->getTheInput(a);
}
}
|