Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <deque>
- #include <iostream>
- class Connection
- {
- private:
- char symb;
- int startState;
- int *states[2];
- public:
- Connection() { symb = NULL; states[0] = NULL; states[1] = NULL; };
- ~Connection() {};
- Connection(char s, int start, int fin)
- {
- symb = s;
- startState = start;
- states[0] = &fin;
- }
- void patch(Connection cnt1, Connection cnt2, int end1)
- {
- *cnt1.states[end1] = cnt2.startState;
- }
- int getStartState()
- {
- return startState;
- }
- void getInfo()
- {
- std::cout << startState << "---" << symb << "--> " << *states[0];
- }
- int* getFinStates()
- {
- if (states[1] == NULL)
- return states[0];
- else
- return *states;
- }
- };
- int main()
- {
- char *txt = new char[255];
- int counter = 0;
- int i = 0;
- while (std::cin >> txt[i])
- i++;
- txt[i] = '\0';
- std::cout << std::endl;
- if (txt[0] == '\0')
- {
- std::cout << "String is empty" << std::endl;
- return 0;
- }
- std::deque<Connection> FSM(0);
- i = 0;
- while (txt[i] != '\0')
- {
- switch (txt[i])
- {
- default:
- {
- counter = counter + 1;
- Connection *cnt = new Connection(txt[i], counter-1, counter);
- FSM.push_back(*cnt);
- delete cnt;
- break;
- }
- case '.':
- {
- i++; counter = counter + 1;
- Connection *cnt1 = new Connection(txt[i], FSM[FSM.size() - 1].getFinStates()[0], counter);
- FSM.push_back(*cnt1);
- delete cnt1;
- break;
- }
- }
- i++;
- }
- for (int j = 0; j < FSM.size(); j++)
- FSM[j].getInfo();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment