Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct tf {
  4. char from, to, input;
  5. };
  6.  
  7. bool check_lang(struct tf func[], int fn, char init, char final, char str[])
  8. {
  9. int i = 0, j = 0;
  10. char current_state = init;
  11. while(str[j] != '\0')
  12. {
  13. if(func[i].from == current_state)
  14. {
  15. if(func[i].input == str[j])
  16. {
  17. current_state = func[i].to;
  18. j++;
  19. }
  20. }
  21. i++;
  22. if(i == fn)
  23. {
  24. i = 0;
  25. j++;
  26. }
  27. }
  28. return (current_state == final) ? true : false;
  29. }
  30.  
  31. int main()
  32. {
  33. int tf_n, i, lang_n;
  34. char start_state, final_state;
  35. scanf("%d", &tf_n);
  36. getchar();
  37. struct tf funcs[tf_n];
  38. scanf("%c %c", &start_state, &final_state);
  39. getchar();
  40. for(i = 0; i < tf_n; i++)
  41. {
  42. char x, y, z;
  43. scanf("%c %c %c", &x, &y, &z);
  44. getchar();
  45. funcs[i].from = x;
  46. funcs[i].to = y;
  47. funcs[i].input = z;
  48. }
  49. scanf("%d", &lang_n);
  50. getchar();
  51. for(i = 0; i < lang_n; i++)
  52. {
  53. char ch[10000];
  54. scanf("%s", ch);
  55. printf("%s", (check_lang(funcs, tf_n, start_state,
  56. final_state, ch) ? "CORRECT\n" : "INCORRECT\n"));
  57. }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement