Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- char str[100];
- cout<<"Enter string";
- cin>>str;
- int i=0;
- int q=0;
- while(str[i])
- {
- switch(q)
- {
- case 0:
- if(str[i]=='a')
- q=1;
- break;
- case 1:
- if(str[i]=='a')
- q=1;
- if(str[i]=='b')
- q=2;
- if(str[i]=='c')
- q=0;
- break;
- case 2:
- if(str[i]=='a')
- q=1;
- if(str[i]=='b')
- q=0;
- if(str[i]=='c')
- q=3;
- break;
- case 3:
- if(str[i]=='a')
- q=4;
- if(str[i]=='b')
- q=3;
- if(str[i]=='c')
- q=3;
- break;
- case 4:
- if(str[i]=='a')
- q=4;
- if(str[i]=='b')
- q=5;
- if(str[i]=='c')
- q=3;
- break;
- case 5:
- if(str[i]=='a')
- q=4;
- if(str[i]=='b')
- q=3;
- if(str[i]=='c')
- q=0;
- break;
- }
- i++;
- }
- if(q==3 || q==4 ||q==5)
- cout<<"\n String is valid";
- else
- cout<<"\n String is invalid ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment