Advertisement
Guest User

Untitled

a guest
Dec 31st, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. #include <map>
  2. int main()
  3. {
  4. int i = 0;
  5. return 0;
  6. }
  7. ------------------------------------------
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. #include "Tree.h"
  15. User::User(Tree_node * Top)
  16. {
  17. Start_source_tree = Top;
  18. Top_ = *Top;
  19. Buf_.IsAHum_ = false;
  20. Buf_.Name_of_node = "Буферное дерево";
  21. }
  22. User :: User ()
  23. {
  24. }
  25. void
  26. User :: Change_point (Tree_node *Top)
  27. {
  28. Start_source_tree = Top;
  29. Top_ = *Top;
  30. Buf_.IsAHum_ = false;
  31. Buf_.Name_of_node = "Буферное дерево";
  32. }
  33. void
  34. User::Select(Tree_node * Top_node_source, string Rule)
  35. {
  36. if (Top_node_source -> Name_of_node == Rule)
  37. {
  38. Buf_.Down.insert(Buf_.Down.end(), Top_node_source);
  39. }
  40. else
  41. {
  42. for (unsigned int n =0; n < Top_node_source -> Down.size(); ++n)
  43. {
  44. Select(Top_node_source -> Down[n], Rule);
  45. }
  46. }
  47.  
  48.  
  49. }
  50. void
  51. User::Print(Tree_node Tree_node_source, vector<string> Rule_print)
  52. {
  53. if(Tree_node_source.IsAHum_ == true)
  54. {
  55. if (Rule_print[0] != "~ALL~")
  56. {
  57. for (unsigned int i = 0; i < Rule_print.size(); ++i)
  58. {
  59. cout << Rule_print[i] << " ";
  60. }
  61. cout << "\n";
  62. for(unsigned int i = 0; i < Rule_print.size(); ++i)
  63. {
  64. cout << "(" << Tree_node_source.Work[Rule_print[i]].Duration << ")~~" << Tree_node_source.Work[Rule_print[i]].Description <<" ";
  65. }
  66. cout << "\n";
  67. }
  68. else
  69. {
  70. cout << Tree_node_source.Name_of_node <<"\n-------------\n";
  71. for (map <string, Description_of_work>::iterator i = Tree_node_source.Work.begin(); i != Tree_node_source.Work.end(); ++i)
  72. {
  73. cout << i -> first << " (" << i -> second.Duration << ") " << i -> second.Description <<"\n";
  74. }
  75. cout <<"-------------\n";
  76. }
  77. }
  78. else
  79. {
  80. for(unsigned int n = 0; n < Tree_node_source.Down.size(); n++)
  81. {
  82. Print(*(Tree_node_source.Down[n]), Rule_print);
  83. }
  84. }
  85.  
  86. }
  87. int
  88. User::Parse (string Inp_str)
  89. {
  90. string Command;
  91. Command = Split_str(Inp_str, " ");
  92. if (Command == "SELECT")
  93. {
  94. Buf_.Down.clear();
  95. Select(& Top_, Inp_str);
  96. Top_.Down.clear();
  97. for (unsigned int i = 0; i < Buf_.Down.size(); i++)
  98. {
  99. Top_.Down.insert(Top_.Down.end(), Buf_.Down[i]);
  100. }
  101. return 1;
  102. }
  103. else if (Command == "ADD")
  104. {
  105. Tree_node * Tm_Buf_ = Start_source_tree;
  106. while (Inp_str.substr(0, 1) != "[" && Inp_str.length()>0)
  107. {
  108. string Way = Split_str(Inp_str, "|");
  109. Tm_Buf_ = Add(Tm_Buf_, Way);
  110. }
  111. if (Inp_str.substr(0,1) != "[")
  112. {
  113. return 0;
  114. }
  115. Split_str (Inp_str, "[");
  116. string Name_of_worker = Split_str(Inp_str, "|~");
  117. map<string, Description_of_work> New_work;
  118. while (Inp_str != "]")
  119. {
  120. string Name = Split_str (Inp_str, "~");
  121. Split_str (Inp_str, "(");
  122. New_work[Name].Duration = stoi(Split_str(Inp_str, ")"));
  123. New_work[Name].Description = Split_str(Inp_str, "~|" );
  124. }
  125. Add_worker (Tm_Buf_, Name_of_worker, New_work);
  126. return 1;
  127. }
  128. else if (Command == "DELETE")
  129. {
  130. Tree_node * Now_node = Start_source_tree;
  131. Tree_node *Prev_node;
  132. string Way;
  133. unsigned int n = 0;
  134. while (Inp_str.length() > 0)
  135. {
  136. int i = 0;
  137. Way = Split_str (Inp_str, "~");
  138. for (n = 0; n < Now_node -> Down.size(); ++n)
  139. {
  140.  
  141. if (Now_node -> Down[n]->Name_of_node == Way)
  142. {
  143. Prev_node = Now_node;
  144. Now_node = Now_node -> Down[n];
  145. i++;
  146.  
  147. break;
  148. }
  149. }
  150. if (i == 0)
  151. {
  152. cout << Way <<" "<< Inp_str<< "Ф\n";
  153. return 2;
  154. //ИСКЛЮЧЕНИЕ
  155. }
  156. }
  157. if (Now_node -> IsAHum_ == false)
  158. {
  159. //ИСКЛЮЧЕНИЕ
  160. }
  161. Prev_node -> Down.erase (Prev_node -> Down.begin() + n );
  162. delete Now_node;
  163. return 1;
  164. }
  165. else if (Command == "PRINT")
  166. {
  167. vector <string> Rules;
  168. if (Inp_str == "~ALL~")
  169. {
  170. Rules.insert(Rules.end(), "~ALL~");
  171. Print (Top_, Rules);
  172. return 1;
  173. }
  174. while(Inp_str.length() > 0)
  175. {
  176. string Rule = Split_str(Inp_str, " ");
  177. Rules.insert(Rules.end(),Rule);
  178. }
  179. Print (Top_, Rules);
  180. return 1;
  181. }
  182. else if (Command == "CLEAR", Inp_str.length() == 0)
  183. {
  184. Top_ = *Start_source_tree;
  185. return 1;
  186. }
  187. else if (Command == "END")
  188. {
  189. return 2;
  190. }
  191. else
  192. {
  193. return 0;
  194. }
  195. }
  196. Tree_node*
  197. User::Add (Tree_node * Top_node, string way)
  198. {
  199. if (Top_node -> IsAHum_ == true)
  200. {
  201. }//ОШИБКА ТИПА НЕЛЬЗЯ ПОДЧИНЕННЫХ ВЫДАВАТЬ ЧЕЛОВЕКУ
  202. for(unsigned int n = 0; n < Top_node -> Down.size(); ++n)
  203. {
  204. if ((Top_node -> Down[n]) -> Name_of_node == way)
  205. {
  206. return Top_node -> Down[n];
  207. }
  208. }
  209. Tree_node * Return_node = new Tree_node;
  210. Return_node -> IsAHum_ = false;
  211. Return_node -> Name_of_node = way;
  212. Top_node -> Down.insert (Top_node -> Down.end(), Return_node);
  213. return Return_node;
  214. }
  215. void
  216. User::Add_worker (Tree_node * Top_node, string Name_of_worker, map<string, Description_of_work> Work_in)
  217. {
  218. if(Top_node -> IsAHum_ == true)
  219. {
  220. }//ОШИБКА
  221. for (unsigned int i =0; i < Top_node -> Down.size(); ++i)
  222. {
  223. if (Top_node -> Down[i] -> Name_of_node == Name_of_worker)
  224. {
  225. //ОШИБКА
  226. return;
  227. }
  228. }
  229. Tree_node * New_node = new Tree_node;
  230. New_node -> Name_of_node = Name_of_worker;
  231. New_node -> IsAHum_ = true;
  232. Top_node -> Down.insert(Top_node -> Down.end(), New_node) ;
  233. New_node -> Work = Work_in;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement