Advertisement
IntelBohdan

Untitled

May 6th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. #include <cassert>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <sstream>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <cstdio>
  9. using namespace std;
  10.  
  11. struct TCar
  12. {
  13. int uroven;
  14. //int predek;
  15. int typprvku;
  16. string text;
  17. int index;
  18. string shape;
  19. //string pomoc;
  20.  
  21. };
  22.  
  23.  
  24. class CResult
  25. {
  26. public:
  27. CResult(void) {vectorNr=0; urmax=0;}
  28. void getline1 (void);
  29. void print (void);
  30. int typ (const string s);
  31. void printvector (void);
  32. string typstr (const string buffer);
  33. void zacatek (void);
  34.  
  35. private:
  36. vector <TCar> myvector;
  37. //string buffer;
  38. int vectorNr;
  39. int urmax;
  40.  
  41.  
  42.  
  43. };
  44.  
  45. void CResult::getline1 (void)
  46. {
  47.  
  48. int probel=0;
  49. string buffer;
  50. char c;
  51. TCar x;
  52. char buffer1[1000];
  53. string buffer2;
  54. //string lomitko='\';
  55. char lomitko='\\';
  56. //string n="\n";
  57. char n='n';
  58. int k=0;
  59. string buffer3;
  60. //int typprvku=0;
  61.  
  62.  
  63. c = cin.get();
  64. while (c == ' ')
  65. {
  66. c = cin.get();
  67. probel++;
  68. }
  69.  
  70. cin.unget();
  71. cin >> buffer ;
  72.  
  73.  
  74. x.typprvku = typ(buffer);
  75. x.shape = typstr(buffer);
  76.  
  77. c = cin.get();
  78. if (c != ' ')
  79. cin.unget();
  80.  
  81.  
  82. if (x.typprvku == 6)
  83. {
  84. cin >> buffer2 ;
  85. }
  86. c = cin.get();
  87. if (c != ' ')
  88. cin.unget();
  89.  
  90. getline (cin, buffer);
  91. if (x.typprvku == 6)
  92. {
  93. buffer3=buffer;
  94. buffer = buffer2 +lomitko + n + buffer3;
  95. }
  96.  
  97.  
  98. if (x.typprvku == 1)
  99. {
  100. for (int j=0; buffer[j] != '\0';j++)
  101. {
  102.  
  103. if (buffer[j] == '=')
  104. {
  105.  
  106. buffer1[k] = '\0';
  107. buffer2=buffer1;
  108. k=0;
  109. continue;
  110. }
  111. buffer1[k] = buffer[j];
  112. k++;
  113. }
  114. buffer1[k]='\0';
  115. buffer=buffer2 +lomitko + n +buffer1;
  116. }
  117.  
  118.  
  119. x.uroven = probel;
  120. x.text = buffer;
  121. x.index = vectorNr;
  122.  
  123. if (probel > urmax)
  124. urmax=probel;
  125.  
  126.  
  127. myvector.push_back(x);
  128. vectorNr++;
  129.  
  130. c=cin.get();
  131. if ( c != EOF)
  132. {
  133. cin.unget();
  134. getline1();
  135. }
  136.  
  137.  
  138. }
  139.  
  140. int CResult::typ (const string buffer)
  141. {
  142. int typprvku=0;
  143. if (buffer == "#attribute")
  144. typprvku = 1;
  145. else if (buffer == "#cdata-section")
  146. typprvku = 2;
  147. else if (buffer == "#comment")
  148. typprvku = 3;
  149. else if (buffer == "#element")
  150. typprvku = 4;
  151. else if (buffer == "#entity-reference")
  152. typprvku = 5;
  153. else if (buffer == "#processing-instruction")
  154. typprvku = 6;
  155. else if (buffer == "#text")
  156. typprvku = 7;
  157.  
  158.  
  159.  
  160.  
  161. return typprvku;
  162.  
  163.  
  164. }
  165.  
  166.  
  167. string CResult::typstr (const string buffer)
  168. {
  169.  
  170. string typ;
  171. if (buffer == "#attribute")
  172. typ = "diamond";
  173. else if (buffer == "#cdata-section")
  174. typ = "trapezium";
  175. else if (buffer == "#comment")
  176. typ = "note";
  177. else if (buffer == "#element")
  178. typ = "circle";
  179. else if (buffer == "#entity-reference")
  180. typ = "oval";
  181. else if (buffer == "#processing-instruction")
  182. typ = "triangle";
  183. else if (buffer == "#text")
  184. typ = "plaintext";
  185.  
  186. return typ;
  187. }
  188.  
  189. void CResult::print (void)
  190. {
  191. cout << "digraph {" << endl;
  192. int max=0;
  193.  
  194. for (auto it=myvector.begin(); it != myvector.end(); it++)
  195. cout << it -> index << "[label=\"" << it -> text << "\",shape=" << it->shape << "]" << endl;
  196.  
  197. // for (auto it=myvector.begin(); it != myvector.end(); it++)
  198. // cout << it -> index >> "->"
  199. //max=0;
  200.  
  201. for (int k=0; k <= urmax ; k++ )
  202. {
  203.  
  204.  
  205. for (int i=0; i < vectorNr ; i++)
  206. {
  207. if (myvector[i].uroven == k)
  208. max=i;
  209.  
  210. if ( myvector[i].uroven == k + 1 )
  211. cout << myvector[max].index << "->" << myvector[i].index << endl;
  212.  
  213.  
  214. }
  215. }
  216.  
  217.  
  218. cout << "}";
  219.  
  220.  
  221. }
  222.  
  223. void CResult::printvector (void)
  224. {
  225. for (auto it=myvector.begin(); it != myvector.end(); it++)
  226. cout << "uroven= " << it -> uroven << " index= "
  227. << it -> index << " typprvku= " << it -> typprvku << " shape= "
  228. << it->shape << " =" << it -> text << "\n";
  229.  
  230. cout << "urmax= " << urmax << "\n";
  231.  
  232. }
  233.  
  234.  
  235. void CResult::zacatek (void)
  236. {
  237.  
  238. TCar k;
  239. k.index = vectorNr;
  240. k.uroven = 0;
  241. k.shape ="house";
  242. k.typprvku=0;
  243. k.text="/";
  244. myvector.push_back(k);
  245. vectorNr++;
  246.  
  247. }
  248.  
  249.  
  250. int main ( void )
  251. {
  252.  
  253. CResult x;
  254. x.zacatek();
  255. x.getline1();
  256. x.print();
  257.  
  258.  
  259. return 0;
  260. }
  261.  
  262.  
  263.  
  264. digraph {
  265. 0[label="/", shape=house];
  266. 1[label="html", shape=circle];
  267. 2[label="lang\nen", shape=diamond];
  268. 3[label="xml:lang\nen", shape=diamond];
  269. 4[label="xmlns\nhttp://www.w3.org/1999/xhtml", shape=diamond];
  270. 5[label="head", shape=circle];
  271. 6[label="title", shape=circle];
  272. 7[label="FIT CVUT", shape=plaintext];
  273. 8[label="body", shape=circle];
  274. 9[label="Markup used in this document is compatible with ", shape=plaintext];
  275. 10[label="b", shape=circle];
  276. 11[label="XHTML", shape=plaintext];
  277. 12[label="nbsp ", shape=oval];
  278. 13[label=" 1", shape=plaintext];
  279. 14[label=". It should not contain some characters, e.g., ", shape=plaintext];
  280. 15[label="editor\nemph", shape=triangle];
  281. 16[label="<", shape=trapezium];
  282. 17[label="this does not display ", shape=note];
  283. 18[label=".", shape=plaintext];
  284. 0->1;
  285. 1->2;
  286. 1->3;
  287. 1->4;
  288. 1->5;
  289. 1->8;
  290. 5->6;
  291. 8->9;
  292. 8->10;
  293. 8->14;
  294. 8->15;
  295. 8->16;
  296. 8->17;
  297. 8->18;
  298. 6->7;
  299. 10->11;
  300. 10->12;
  301. 10->13;
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement