Tomki

Наметочки-наметки

Mar 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <deque>
  3. #include <iostream>
  4.  
  5. class Connection
  6. {
  7. private:
  8.     char symb;
  9.     int startState;
  10.     int *states[2];
  11. public:
  12.     Connection() { symb = NULL; states[0] = NULL; states[1] = NULL; };
  13.     ~Connection() {};
  14.     Connection(char s, int start, int fin)
  15.     {
  16.         symb = s;
  17.         startState = start;
  18.         states[0] = &fin;
  19.     }
  20.     void patch(Connection cnt1, Connection cnt2, int end1)
  21.     {
  22.         *cnt1.states[end1] = cnt2.startState;
  23.     }
  24.     int getStartState()
  25.     {
  26.         return startState;
  27.     }
  28.     void getInfo()
  29.     {
  30.         std::cout << startState << "---" << symb << "--> " << *states[0];
  31.     }
  32.     int* getFinStates()
  33.     {
  34.         if (states[1] == NULL)
  35.             return states[0];
  36.         else
  37.             return *states;
  38.     }
  39. };
  40.  
  41. int main()
  42. {
  43.     char *txt = new char[255];
  44.     int counter = 0;
  45.     int i = 0;
  46.     while (std::cin >> txt[i])
  47.         i++;
  48.     txt[i] = '\0';
  49.     std::cout << std::endl;
  50.     if (txt[0] == '\0')
  51.     {
  52.         std::cout << "String is empty" << std::endl;
  53.         return 0;
  54.     }
  55.  
  56.     std::deque<Connection> FSM(0);
  57.     i = 0;
  58.     while (txt[i] != '\0')
  59.     {
  60.         switch (txt[i])
  61.         {
  62.         default:
  63.         {
  64.             counter = counter + 1;
  65.             Connection *cnt = new Connection(txt[i], counter-1, counter);
  66.             FSM.push_back(*cnt);
  67.             delete cnt;
  68.             break;
  69.         }
  70.         case '.':
  71.         {
  72.             i++; counter = counter + 1;
  73.             Connection *cnt1 = new Connection(txt[i], FSM[FSM.size() - 1].getFinStates()[0], counter);
  74.             FSM.push_back(*cnt1);
  75.             delete cnt1;
  76.             break;
  77.         }
  78.         }
  79.         i++;
  80.        
  81.     }
  82.     for (int j = 0; j < FSM.size(); j++)
  83.         FSM[j].getInfo();
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment