Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MPAuto.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <vector>
- #include <string>
- #include <iostream>
- #include <deque>
- using namespace std;
- class pushDownAuto
- {
- private:
- vector<char> memory;
- int activeMatrix;
- public:
- pushDownAuto()
- {
- memory.empty();
- activeMatrix = 1;
- }
- void pushA()
- {
- memory.push_back('A');
- }
- void pop()
- {
- memory.pop_back();
- }
- void pushB()
- {
- memory.push_back('B');
- }
- void pushC()
- {
- memory.push_back('C');
- }
- int parse(deque<char>& txt)
- {
- while (txt.size() != 0)
- {
- if (activeMatrix == 1)
- {
- if (memory.empty())
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- return 0;
- case '1':
- {
- pushA(), txt.pop_front();
- break;
- }
- case '\0':
- return 0;
- }
- }
- else if (memory.back() == 'A')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- return 0;
- case '1':
- {
- pop(), pushB(), txt.pop_front();
- break;
- }
- case '\0':
- return 0;
- }
- }
- else if (memory.back() == 'B')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- activeMatrix = 2; break;
- case '1':
- pushA(), txt.pop_front(); break;
- case '\0':
- return 0;
- }
- }
- }
- else if (activeMatrix == 2)
- {
- if (memory.back() == 'B')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- pushC(), txt.pop_front(); break;
- case '1':
- return 0;
- case '\0':
- return 0;
- }
- }
- else if (memory.back() == 'C')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- pushC(), txt.pop_front(); break;
- case '1':
- activeMatrix = 3; break;
- case '\0':
- return 0;
- }
- }
- }
- else if (activeMatrix == 3)
- {
- if (memory.back() == 'C')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- return 0;
- case '1':
- pop(), txt.pop_front(); break;
- case '\0':
- return 0;
- }
- }
- else if (memory.back() == 'B')
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- activeMatrix = 4; break;
- case '1':
- return 0;
- case '\0':
- return 0;
- }
- }
- }
- else if (activeMatrix == 4)
- {
- if (memory.empty())
- {
- if (txt[0] == '\0')
- return 1;
- else
- return 0;
- }
- else
- {
- switch (txt[0])
- {
- default:
- break;
- case '0':
- pop(), txt.pop_front(); break;
- case '1':
- return 0;
- case '\0':
- return 0;
- }
- }
- }
- }
- }
- void getInfo()
- {
- cout << memory.size();
- }
- };
- int main()
- {
- deque<char> input;
- string txt;
- cin >> txt;
- int i = 0;
- while (txt[i] != '\0')
- {
- input.push_back(txt[i]);
- i++;
- }
- input.push_back(txt[i]);
- pushDownAuto *obj = new pushDownAuto();
- if (obj->parse(input))
- cout << "correct\n";
- else cout << "incorrect\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment