Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- intcheckAlpha(char C)
- {
- if (C>=65 && C<=90) return 1;
- else if (C>=97 && C<=122) return 1;
- else if (C==95) return 1;
- else return 0;
- }
- intcheckDigit(char C)
- {
- if (C>=48 && C<=56) return 1;
- else return 0;
- }
- int main()
- {
- stringstr;cout<<"Enter a identifier";cin>>str;
- int state=1,length=str.length();
- inti=0;
- while (i<length)
- {
- if(state==1 &&checkAlpha(str[i])==1)
- {
- state=2;i++;
- }
- else if(state==2 &&checkAlpha(str[i])==1)
- {
- state=2;i++;
- }
- else if(state==2 &&checkDigit(str[i])==1)
- {
- state=2;i++;
- }
- else{state=3;break;}
- }
- if(state==2)
- cout<<"Accepted..."<<endl;
- if(state==3)
- cout<<"Rejected..."<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement