Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum TCharType {ctUnknown, ctLetters, ctDoubleDot, ctSlash, ctGrOK};
- const int TStateCount = 8;
- const int TCharTypeCount = 5;
- int transitions[TStateCount][TCharTypeCount] = {
- { 0, 0, 0, 0, 0 },
- { 0, 2, 0, 0, 0 },
- { 0, 0, 3, 0, 0 },
- { 0, 0, 0, 4, 0 },
- { 0, 0, 0, 0, 5 },
- { 0, 0, 0, 6, 5 },
- { 0, 0, 0, 0, 7 },
- { 0, 0, 0, 6, 7 }
- };
- bool isFinalState[TStateCount] = { false, false, false, false, true, false, true };
- TCharType getCharType(char c)
- {
- if ((c >= 'A') && (c <= 'Z'))
- {
- return ctLetters;
- }
- else
- {
- if (c == ':')
- return ctDoubleDot;
- if (c == '\\')
- return ctSlash;
- if ((c == '*') || (c == '|') || (c == '\\') || (c == ':') || (c == '"') || (c == '<') || (c == '>') || (c == '?') || (c == '/'))
- return ctUnknown;
- else
- return ctGrOK;
- }
- }
- bool checkString(string s)
- {
- int state = 1;
- for(int i = 0; i < s.length(); i++)
- state = transitions[state, getCharType(s[i])];
- return isFinalState[state];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement