Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int main() {
  5. ifstream Fin;
  6. ofstream Fout;
  7. Fin.open("problem1.in");
  8. Fout.open("problem1.out");
  9. bool exists = false;
  10. string s;
  11. Fin >> s;
  12. int n, m, k;
  13. Fin >> n >> m >> k;
  14. int d[n][n][26];
  15. for (int i = 0; i < n; i++) {
  16. for (int j = 0; j < n; j++) {
  17. for (int z = 0; z < 26; z++) {
  18. d[i][j][z] = 0;
  19. }
  20. }
  21. }
  22. int end[k];
  23. for (int i = 0; i < k; i++) {
  24. Fin >> end[i];
  25. }
  26. for (int i = 0; i < m; i++) {
  27. int first, second;
  28. Fin >> first >> second;
  29. char word;
  30. Fin >> word;
  31. d[first - 1][second - 1][word - 'a'] = 1;
  32. }
  33. int currentState = 0;
  34. for (int j = 0; j < s.size(); j++) {
  35. bool stateExists = false;
  36. char currentWord = s[j];
  37. for (int i = 0; i < n; i++) {
  38. if (d[currentState][i][currentWord - 'a'] == 1) {
  39. currentState = i;
  40. stateExists = true;
  41. if (j == s.size() - 1) {
  42. exists = true;
  43. }
  44. }
  45. }
  46. if (!stateExists) {
  47. Fout << "Rejects";
  48. break;
  49. }
  50. }
  51. if (exists) {
  52. bool contains = false;
  53. for (int i = 0; i < k; i++) {
  54. if (end[i] == currentState + 1) {
  55. contains = true;
  56. Fout << "Accepts";
  57. break;
  58. }
  59. }
  60. if (!contains) {
  61. Fout << "Rejects";
  62. }
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement