Time:10-11
# include & lt; Iostream> #include #include #include #include #include #include #include #include #include #include #include #include //# include & lt; Sstream> //# include & lt; Regex> //# include & lt; Functional> using namespace std; Struct Node {The string data. SetSet The file; Bool operator<(const Node& N) const {Return the data & lt; N.d ata. } }; Bool CMP (Node * a, Node * b) {Return a - & gt; The data & lt; B - & gt; data; } Void insert (the root Node * and string STR) {If (STR) empty ()) return; Node * n=the new Node (); Int index=STR. Find (' \ \ '); cout <"Find_index:" & lt; If (index!=1) {String s=STR. Substr (0, index); N - & gt; Data=https://bbs.csdn.net/topics/s; For (auto& It: root - & gt; Link) If (it - & gt; Data=https://bbs.csdn.net/topics/=n -> data) {N=it; break; } Root - & gt; The link. The insert (n); STR=STR. Substr (index + 1); Insert (n, STR); } The else {Root - & gt; File. The insert (STR); } return; } Void print (Node root, int n) {for (int i=0; i cout <""; cout For (auto& It: root) link) Print (* it, n + 1); For (auto& It: root file) {for (int i=0; i cout <""; cout } } Int main () {int N; String STR. The Node root, n. Root. Data="https://bbs.csdn.net/topics/root"; Cin & gt;> N; While (N -) {Cin & gt;> STR; Insert (& amp; Root, STR); } Print (root, 0); return 0; }
Page link:https//www.codepudding.com/Backend/62490.html