Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct tf {
- char from, to, input;
- };
- bool check_lang(struct tf func[], int fn, char init, char final, char str[])
- {
- int i = 0, j = 0;
- char current_state = init;
- while(str[j] != '\0')
- {
- if(func[i].from == current_state)
- {
- if(func[i].input == str[j])
- {
- current_state = func[i].to;
- j++;
- }
- }
- i++;
- if(i == fn)
- {
- i = 0;
- j++;
- }
- }
- return (current_state == final) ? true : false;
- }
- int main()
- {
- int tf_n, i, lang_n;
- char start_state, final_state;
- scanf("%d", &tf_n);
- getchar();
- struct tf funcs[tf_n];
- scanf("%c %c", &start_state, &final_state);
- getchar();
- for(i = 0; i < tf_n; i++)
- {
- char x, y, z;
- scanf("%c %c %c", &x, &y, &z);
- getchar();
- funcs[i].from = x;
- funcs[i].to = y;
- funcs[i].input = z;
- }
- scanf("%d", &lang_n);
- getchar();
- for(i = 0; i < lang_n; i++)
- {
- char ch[10000];
- scanf("%s", ch);
- printf("%s", (check_lang(funcs, tf_n, start_state,
- final_state, ch) ? "CORRECT\n" : "INCORRECT\n"));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement