Advertisement
MaksNew

Untitled

Dec 1st, 2021
1,207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. enum TCharType {ctUnknown, ctLetters, ctDoubleDot, ctSlash, ctGrOK};
  2.  
  3. const int TStateCount = 8;
  4. const int TCharTypeCount = 5;
  5.  
  6. int transitions[TStateCount][TCharTypeCount] = {
  7.     { 0, 0, 0, 0, 0 },
  8.     { 0, 2, 0, 0, 0 },
  9.     { 0, 0, 3, 0, 0 },
  10.     { 0, 0, 0, 4, 0 },
  11.     { 0, 0, 0, 0, 5 },
  12.     { 0, 0, 0, 6, 5 },
  13.     { 0, 0, 0, 0, 7 },
  14.     { 0, 0, 0, 6, 7 }
  15. };
  16.  
  17. bool isFinalState[TStateCount] = { false, false, false, false, true, false, true };
  18.  
  19. TCharType getCharType(char c)
  20. {
  21.     if ((c >= 'A') && (c <= 'Z'))
  22.     {
  23.         return ctLetters;
  24.     }
  25.     else
  26.     {
  27.         if (c == ':')
  28.             return ctDoubleDot;
  29.         if (c == '\\')
  30.             return ctSlash;
  31.         if ((c == '*') || (c == '|') || (c == '\\') || (c == ':') || (c == '"') || (c == '<') || (c == '>') || (c == '?') || (c == '/'))
  32.             return ctUnknown;
  33.         else
  34.             return ctGrOK;
  35.     }
  36. }
  37.  
  38. bool checkString(string s)
  39. {
  40.     int state = 1;
  41.     for(int i = 0; i < s.length(); i++)
  42.         state = transitions[state, getCharType(s[i])];
  43.     return isFinalState[state];
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement