Guest User

Untitled

a guest
Sep 11th, 2019
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. #include <fstream>
  4.  
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. ifstream f("1.txt");
  10.  
  11. class Turing {
  12. private:
  13. string cState, nState;
  14. char cSymbol, nSymbol, dir;
  15. public:
  16. Turing(char a, char b, char c, char d, char e) {
  17. cState = a;
  18. cSymbol = b;
  19. nSymbol = c;
  20. dir = d;
  21. nState = e;
  22. }
  23.  
  24. void Input() {
  25. string a, e;
  26. char b, c, d;
  27. f >> a >> b >> c >> d >> e;
  28. cState = a;
  29. cSymbol = b;
  30. nSymbol = c;
  31. dir = d;
  32. nState = e;
  33. }
  34.  
  35. void Machine(vector < Turing > v, int Pos, string Tape) {
  36. int i = 0, steps = 0;
  37. string t1 = "0";
  38. char t2 = '0';
  39. while (true) {
  40. if (v[i].cState == t1) {
  41. if (Tape[Pos] == v[i].cSymbol) {
  42. t2 = Tape[Pos];
  43. Tape[Pos] = v[i].nSymbol;
  44. t1 = v[i].nState;
  45.  
  46. if (v[i].dir == 'L') {
  47. Pos--;
  48. } else if (v[i].dir == 'R') {
  49. Pos++;
  50. }
  51. if (t2 != v[i].nSymbol) {
  52. cout << Tape << endl;
  53. steps++;
  54. }
  55. i = 0;
  56. } else {
  57. i++;
  58. }
  59. } else {
  60. i++;
  61. }
  62. if (i >= v.size()) {
  63. cout << steps;
  64. break;
  65. }
  66. }
  67. }
  68. };
  69.  
  70. int main() {
  71. int Pos;
  72. string Tape;
  73. f >> Pos >> Tape;
  74. vector < Turing > v;
  75. Turing t(0, 0, 0, 0, 0);
  76.  
  77. while (true) {
  78. t.Input();
  79. v.push_back(t);
  80. if (f.eof()) {
  81. break;
  82. }
  83. }
  84. t.Machine(v, Pos, Tape);
  85. }
RAW Paste Data