Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- ifstream f("1.txt");
- class Turing {
- private:
- string cState, nState;
- char cSymbol, nSymbol, dir;
- public:
- Turing(char a, char b, char c, char d, char e) {
- cState = a;
- cSymbol = b;
- nSymbol = c;
- dir = d;
- nState = e;
- }
- void Input() {
- string a, e;
- char b, c, d;
- f >> a >> b >> c >> d >> e;
- cState = a;
- cSymbol = b;
- nSymbol = c;
- dir = d;
- nState = e;
- }
- void Machine(vector < Turing > v, int Pos, string Tape) {
- int i = 0, steps = 0;
- string t1 = "0";
- char t2 = '0';
- while (true) {
- if (v[i].cState == t1) {
- if (Tape[Pos] == v[i].cSymbol) {
- t2 = Tape[Pos];
- Tape[Pos] = v[i].nSymbol;
- t1 = v[i].nState;
- if (v[i].dir == 'L') {
- Pos--;
- } else if (v[i].dir == 'R') {
- Pos++;
- }
- if (t2 != v[i].nSymbol) {
- cout << Tape << endl;
- steps++;
- }
- i = 0;
- } else {
- i++;
- }
- } else {
- i++;
- }
- if (i >= v.size()) {
- cout << steps;
- break;
- }
- }
- }
- };
- int main() {
- int Pos;
- string Tape;
- f >> Pos >> Tape;
- vector < Turing > v;
- Turing t(0, 0, 0, 0, 0);
- while (true) {
- t.Input();
- v.push_back(t);
- if (f.eof()) {
- break;
- }
- }
- t.Machine(v, Pos, Tape);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement