vadimk772336

2 класса

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