fork(6) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<string> split(string& to_split, char separator = ' ')
  8. {
  9. vector<string> result = { "" };
  10. for (int i = 0; i < to_split.size(); i++)
  11. {
  12. if (to_split[i] == separator)
  13. {
  14. result.push_back("");
  15. }
  16. else
  17. {
  18. result[result.size() - 1] += to_split[i];
  19. }
  20. }
  21.  
  22. return result;
  23. }
  24.  
  25. void strip(string& to_strip, char to_erase = ' ')
  26. {
  27. while (to_strip[0] == to_erase)
  28. {
  29. to_strip.erase(0, 1);
  30. }
  31. if (to_strip.size() == 0)
  32. {
  33. return;
  34. }
  35. while (to_strip[to_strip.size() - 1] == to_erase)
  36. {
  37. to_strip.erase(to_strip.size() - 1, to_strip.size());
  38. }
  39. }
  40. string wciecia(int wciecie)
  41. {
  42. string result = "";
  43. for (int i = 0; i < wciecie; i++)
  44. {
  45. result += " ";
  46. }
  47.  
  48. return result;
  49. }
  50.  
  51. int main()
  52. {
  53. string rzad, tag;
  54. vector<string> rzad_po_split, tag_po_split, atr_po_split;
  55. int wciecie = 0;
  56. bool dodaj_wciecie;
  57. while (getline(cin, rzad))
  58. {
  59. while (rzad.find('<') != string::npos)
  60. {
  61. tag = rzad.substr(rzad.find('<') + 1, rzad.find('>') - rzad.find('<') - 1);
  62. rzad.erase(rzad.find('<'), rzad.find('>') - rzad.find('<') + 1);
  63. if (tag[0] == '/')
  64. {
  65. wciecie--;
  66. }
  67. else
  68. {
  69. if (tag[tag.size() - 1] == '/')
  70. {
  71. dodaj_wciecie = false;
  72. tag.erase(tag.size() - 1, tag.size());
  73. }
  74. else
  75. {
  76. dodaj_wciecie = true;
  77. }
  78. strip(tag);
  79. tag_po_split = split(tag);
  80. cout << wciecia(wciecie) << tag_po_split[0] << ':' << endl;
  81. for (int i = 1; i < tag_po_split.size(); i++)
  82. {
  83. atr_po_split = split(tag_po_split[i], '=');
  84. strip(atr_po_split[1], '"');
  85. cout << wciecia(wciecie + 1) << atr_po_split[0] << " = " << atr_po_split[1] << endl;
  86. }
  87. dodaj_wciecie ? wciecie += 1 : NULL;
  88. }
  89. }
  90.  
  91.  
  92. }
  93. }
Success #stdin #stdout 0.01s 5536KB
stdin
Standard input is empty
stdout
Standard output is empty