Home > Back-end >  PTA 7 to 30 directory tree (30 points)
PTA 7 to 30 directory tree (30 points)

Time:10-04

https://pintia.cn/problem-sets/15/problems/857
Where the bug in the 59th line insert function part, should be a problem with the pointer, bosses online on

 

# include & lt; Iostream>
# include & lt; Vector>
# include & lt; Algorithm>
# include & lt; Map>
# include & lt; Unordered_map & gt;
# include & lt; Set>
# include & lt; Cmath>
# include & lt; String>
# include & lt; Queue>
# include & lt; Stack>
# include & lt; List>
# include & lt; Iomanip>
//# include & lt; Sstream>
//# include & lt; Regex>
//# include & lt; Functional>
using namespace std;

Struct Node {
The string data.
Set The link;
Set The file;
Bool operator<(const Node& N) const {
Return the data & lt; N.d ata.
}
};

//void insert (Node& Root, string STR) {
//if (STR. Empty ())
//return;
//the Node n.
//int index=STR. Find (' \ \ ');
//cout & lt; <"Find_index:" & lt; //if (index!=1) {
//the string s=STR. Substr (0, index);
//n.d ata=https://bbs.csdn.net/topics/s;
//if (! Root. Link. Insert (n.) the second)
//for (auto& It: root) link)
//if (it. Data=https://bbs.csdn.net/topics/=n.d ata) {
//n=it;
//break;
//}
//STR=STR. Substr (index + 1);
//insert (n, STR);
//}
//else {
//root. The file. The insert (STR);
//}
//return;
//}

Void insert (Node& Root, string STR) {
If (STR) empty ())
return;
Node * n=(*) malloc (sizeof (Node));
Int index=STR. Find (' \ \ ');
Cout & lt; <"Find_index:" & lt; If (index!=1) {
String s=STR. Substr (0, index);
N - & gt; Data=https://bbs.csdn.net/topics/s;
if (! Root. Link. Insert (* n). The second)
For (auto& It: root) link)
If (it. Data=https://bbs.csdn.net/topics/=n -> data) {
* n=it;
break;
}
STR=STR. Substr (index + 1);
Insert (* n, STR);
}
The else {
Root. The file. The insert (STR);
}
return;
}

Void print (Node root, int n) {
for (int i=0; I & lt; n; + + I)
Cout & lt; <"";
Cout & lt; For (auto& It: root) link)
Print (it, n + 1);
For (auto& It: root file) {
for (int i=0; I & lt; N + 1; + + I)
Cout & lt; <"";
Cout & lt; }
}

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 (root, STR);
}
Print (root, 0);
return 0;
}
  • Related