vadimk772336

экв дка

Mar 8th, 2022 (edited)
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6.  
  7. struct vertex
  8. {
  9.     bool isterminal = false;
  10.     std::vector<struct adj_vertex> adj_list;
  11.     int list_size = 0;
  12.     int number_vertex;
  13.    
  14. };
  15.  
  16. struct adj_vertex
  17. {
  18.     int number_vertex;
  19.     char symbol;
  20. };
  21.  
  22. class Graph
  23. {
  24.     struct vertex* graph;
  25.     int count_edges;
  26.     int count_vertex;
  27.  
  28. public:
  29.     Graph(int count_vertex, int* terminals, int k);
  30.     void addEdge(int i, int j, char symbol);
  31.     void display();
  32. };
  33.  
  34. Graph::Graph(int count_vertex, int* terminals, int k)
  35. {
  36.     graph = new vertex[count_vertex];
  37.     this->count_edges = 0;
  38.     this->count_vertex = count_vertex;
  39.    
  40.     for (int i = 0; i < k; ++i)
  41.     {
  42.         graph[terminals[i]].isterminal = true;
  43.     }
  44. }
  45.  
  46. void Graph::addEdge(int i, int j, char symbol)
  47. {
  48.     adj_vertex buff;
  49.     buff.number_vertex = j;
  50.     buff.symbol = symbol;
  51.  
  52.     graph[i].adj_list.push_back(buff);
  53.  
  54.     graph[i].list_size++;
  55.     this->count_edges++;
  56. }
  57.  
  58.  
  59. void Graph::display()
  60. {
  61.     cout << "\n print:" << endl;
  62.     for (int i = 0; i < this->count_vertex; i++)
  63.     {
  64.         cout << "vertex: " << i << " ";
  65.         if (graph[i].isterminal) cout << "isterminal" << " ";
  66.         int size = graph[i].adj_list.size();
  67.         cout << "adj_vertexes: ";
  68.         for (int j = 0; j < size; ++j)
  69.         {
  70.             cout << "(" << graph[i].adj_list[j].number_vertex << "," << graph[i].adj_list[j].symbol << "); ";
  71.         }
  72.         cout << endl;
  73.     }
  74. }
  75.  
  76.  
  77. Graph ReadDFA(int n, int k, int l)
  78. {
  79.     int u,v;
  80.     char c;
  81.     int t[k];
  82.     for (int i = 0; i < k; ++i)
  83.         cin >> t[i];
  84.    
  85.     Graph DFA(n,t,k);
  86.     for (int i = 0; i < n*l; ++i)
  87.     {
  88.         cin >> u >> c >> v;
  89.         DFA.addEdge(u,v,c);
  90.     }
  91.    
  92.     return DFA;
  93. }
  94.  
  95. int main()
  96. {
  97.  
  98.     //int a[3] = {1,2,3};
  99.     //Graph g(5,a,3);
  100.     //g.addEdge(1,2,'c');
  101.     //g.display();
  102.  
  103.     int n1, k1, l1; //n — колво состояний.  k — колво терминальных состояний.  l — колво букв в алфавите.
  104.     int n2, k2, l2;
  105.  
  106.     cin >> n1 >> k1 >> l1;
  107.     Graph DFA1 = ReadDFA(n1, k1, l1);
  108.    
  109.     cin >> n2 >> k2 >> l2;
  110.     Graph DFA2 = ReadDFA(n2, k2, l2);
  111.    
  112.     //DFA1.display();
  113.    // DFA2.display();
  114.    
  115.    for (int i = 0; i < n1; ++i)
  116.    {
  117.        for (int j = 0; j < n2; ++j)
  118.        {
  119.            
  120.        }
  121.    }
  122.  
  123.    
  124.  
  125.     return 0;
  126. }
  127.  
  128.  
  129.  
Add Comment
Please, Sign In to add comment