1 #include <iostream>
2 #include <vector>
3 #include <string>
4 #include <new>
5 #include <algorithm>
6 using namespace std;
7
8 struct nod;
9
10 struct nod1 {
11 vector<nod *> wen_jian;
12 };
13
14 struct nod {
15 int num;
16 string word;
17 nod1 *next;
18 };
19
20 nod1 *head = new nod1;
21
22 void zhuan( string &str1 )
23 {
24 nod1 *p_rear = head;
25 string str_word;
26 string ::iterator p = str1.begin(),q = str1.end();
27 int n = 0;
28 while ( p != q )
29 {
30 str_word = "";
31 while ( 1 )
32 {
33 str_word += *p++;
34 if ( p == q )
35 break;
36 if ( *p == '\\' )
37 {
38 ++p;
39 break;
40 }
41 }
42 bool y = false;
43 for ( vector<nod *>::iterator p_nod1 = p_rear->wen_jian.begin(),q_nod1 = p_rear->wen_jian.end();p_nod1 != q_nod1; ++p_nod1 )
44 {
45 if ( (*p_nod1)->word == str_word )
46 {
47 p_rear = (*p_nod1)->next;
48 y = true;
49 break;
50 }
51 }
52 if ( y == false )
53 {
54 nod *p_nod = new nod; // 建¨一?个? nod 类え?型í
55 p_nod ->num = n; // 表括?示?层?数簓
56 p_nod ->word = str_word; // 表括?示?此?单蹋?词洙?
57 p_nod ->next = new nod1; //开a放?新?的?层?数簓
58 p_rear->wen_jian.push_back(p_nod);
59 p_rear = p_nod->next;
60
61 }
62 ++n;
63 }
64 }
65
66
67 bool s( nod *p1,nod *p2 )
68 {
69 return p1->word < p2->word;
70 }
71
72 void pai_xu( vector<nod *>::iterator p11,vector<nod *>::iterator q11 )
73 {
74 while ( p11 != q11 )
75 {
76 stable_sort( p11,q11,s );
77 pai_xu( (*p11)->next->wen_jian.begin(),(*p11)->next->wen_jian.end() );
78 ++p11;
79 }
80 }
81
82 void shu_chu( vector<nod *>::iterator p11,vector<nod *>::iterator q11 )
83 {
84 while( p11 != q11 )
85 {
86 for ( int i = 0; i != (*p11)->num; ++i )
87 cout << " ";
88 cout << (*p11)->word << endl;
89 shu_chu( (*p11)->next->wen_jian.begin(),(*p11)->next->wen_jian.end() );
90 ++p11;
91 }
92 }
93
94 int main()
95 {
96 //freopen( "in.txt","r",stdin );
97 string str;
98 int n;
99 cin >> n;
100 while ( n != 0 )
101 {
102 cin >> str;
103 zhuan( str );
104 --n;
105 }
106 nod1 *p = head;
107 pai_xu( p->wen_jian.begin(),p->wen_jian.end() );
108 p = head;
109 shu_chu( p->wen_jian.begin(),p->wen_jian.end() );
110 return 0;
111 }