Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef enum charType
- {
- ctOther,
- ctQout
- } charType;
- int transitions[4][2] =
- {
- {0, 0},
- {0, 2},
- {2, 3},
- {0, 2}
- };
- int isFinalState[4] = { 0, 0, 0, 1 };
- charType getCharType(char c)
- {
- switch (c)
- {
- case '\'':
- return ctQout;
- break;
- default:
- return ctOther;
- break;
- }
- }
- int checkString(char* s)
- {
- int state = 1;
- int i = 0;
- while (*s)
- {
- state = transitions[state][getCharType(s[0])];
- *s++;
- }
- return isFinalState[state];
- }
- int printSubStrings(char* s)
- {
- int i = 1;
- int counter = 0;
- while (*(s + 1))
- {
- if (i > 0 && *s == '\'' && *(s + 1) == '\'')
- {
- printf("\n%d and %d symbols\n", i, i + 1);
- i += 2;
- *s += 2;
- counter++;
- }
- else
- {
- i++;
- *s++;
- }
- }
- return counter;
- }
- int main()
- {
- char s[100];
- gets(s);
- int isCorrect = checkString(s);
- if (isCorrect)
- {
- printf("\nThe string is correct\n");
- int subStringCount = printSubStrings(s);
- subStringCount ? printf("\nThe string contains %d required substrings\n", subStringCount) : printf("\nThe string does not contain required substrings\n");
- }
- else
- printf("The string is not correct\n");
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement