Title: give you the path of the file, the path to the file according to the dictionary order output, if there is a subdirectory, download the parent directory below,
Precede with the same space as the depth.
Parse: Dictionary tree, String. The path is decomposed into multiple levels of folders and files, and then sorted by dictionary order.
The use of the dictionary tree as a stored data structure, easy to query.
Note: Pay attention to the weight.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;const int dictsize = 128;const int nodesize = 20002;const int wordsize = 20002;//tiretypedef struct _tnode{int flag;_tnode *next[dictsize];} Tnode;tnode Dict[nodesize];char list[wordsize][10];class tire{private:int size;int count;tnode* root;public:Tire () { Initial ();} void Initial () {memset (dict, 0, sizeof (dict)); size = Count = 0; root = NewNode ();} Tnode* NewNode () {return &dict[size + +];} int Insert (char* word) {tnode* now = root; for (int i = 0; word[i]; + + i) {if (!now->next[word[i]]) now->next[word[i] = NewNode (); now = now->next[word[i]]; } if (!now->flag) {Now->flag = + + count;strcpy (List[count], word); } return now->flag; }};//typedef struct _dnode{int id[40];} Dnode;dnode Line[wordsize];char Buf[88],temp[10];bool CMP (Dnode A, Dnode b) {for (int i = 0;; + + i) {if (a.id[i] = = 1) retu RN 1;if (B.id[i] = = 1) return 0;int value = strcmp (List[a.id[i]], list[b.id[i]]); if (value) return value < 0; }return 0;} int main () {int t,n,start,count,sum,first = 1;SCANF ("%d", &t), while (T--) {scanf ("%d", &n); Tire Tire;memset (line, 0, sizeof), sum = 0;for (int i = 0; i < n; + + i) {scanf ("%s", buf); start = Count = 0;for (in T j = 0; BUF[J]; + + j) {if (buf[j] = = ' \ \ ') {Line[sum].id[count] = Tire.insert (temp); line[sum].id[++ count] = -1;start = j+1;for (int k = 0 ; K < count; + + k) line[sum+1].id[k] = line[sum].id[k];++ sum;} else {Temp[j-start] = buf[j];temp[j-start+1] = 0;}} Line[sum].id[count] = Tire.insert (temp); line[sum].id[++ count] = -1;++ sum;} Sort (line, line+sum, CMP); count = -1,start = -1;for (int i = 0; i < sum; + + i) {for (int j = 0; Line[i].id[j]! =-1; + + j) {if (line[i].id[j+1] = =-1) {if (j = = Count && start = = LinE[I].ID[J]) break;for (int k = 0; k < J; + + K) printf ("");p rintf ("%s\n", List[line[i].id[j]]); start = Line[i].id[j];count = J;break;}}} if (t) printf ("\ n");} return 0;}
UVa 1556-disk Tree