Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "stdafx.h"
- #include<iostream>
- #include<string.h>
- using namespace std;
- int main()
- {
- char a[13];
- int x,state=0,i;
- for(i=0;i<13;i++)
- {
- a[i]=0;
- }
- cout<<"enter the string\n";
- cin>>a;
- i=0;
- while(a[i]!=0)
- {
- switch(state)
- {
- case 0:
- if(a[i]=='a')
- {
- state=1;
- }
- else if((a[i]=='b')||(a[i]=='c'))
- {
- state=0;
- }
- //flag=0;
- break;
- case 1:
- if(a[i]=='b')
- { state=2;
- }
- else if(a[i]=='c')
- { state=0;}
- else if(a[i]=='a')
- {state=1;}
- //flag=0;
- break;
- case 2:
- if(a[i]=='c')
- {
- state=3;
- //flag=1;
- }
- else if(a[i]=='a')
- {state=1;
- //flag=0;
- }
- else if(a[i]=='b')
- {state=0;
- //flag=0;
- }
- break;
- case 3:
- if(a[i]=='a')
- { state=4;
- }
- else if((a[i]=='b')||(a[i]=='c'))
- { state=4;
- }
- //flag=1;
- break;
- case 4:
- if(a[i]=='b')
- state=5;
- else if(a[i]=='c')
- state=3;
- else if(a[i]=='a')
- state=4;
- //flag=1;
- break;
- case 5:
- if(a[i]=='c')
- {state=0;}
- else if(a[i]=='b')
- { state=3;}
- else if(a[i]=='a')
- {state=4;}
- //flag=1;
- break;
- default:
- cout<<"error..........................";
- break;
- }
- i++;
- }
- cout<<"\n\n";
- if((state==3)||(state==4)||(state==5))
- {
- cout<<"valid string";
- }
- else
- {
- cout<<"invalid string";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment