Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. intcheckAlpha(char C)
  4. {
  5. if (C>=65 && C<=90)   return 1;
  6. else if (C>=97 && C<=122)   return 1;
  7. else if (C==95)   return 1;
  8. else return 0;
  9. }
  10. intcheckDigit(char C)
  11. {
  12. if (C>=48 && C<=56)   return 1;
  13. else return 0;
  14. }
  15. int main()
  16. {
  17. stringstr;cout<<"Enter a identifier";cin>>str;
  18. int state=1,length=str.length();
  19. inti=0;
  20. while (i<length)
  21.     {
  22. if(state==1 &&checkAlpha(str[i])==1)
  23.         {
  24. state=2;i++;
  25.         }
  26. else if(state==2 &&checkAlpha(str[i])==1)
  27.          {
  28. state=2;i++;
  29.          }
  30. else  if(state==2 &&checkDigit(str[i])==1)
  31.       {
  32. state=2;i++;
  33.       }
  34. else{state=3;break;}
  35.     }
  36. if(state==2)
  37. cout<<"Accepted..."<<endl;
  38. if(state==3)
  39. cout<<"Rejected..."<<endl;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement