1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
#define MAXNODE 20000
#define MAXLEN 85
#define MAXWORD 45
map<string, int> m[MAXNODE];
void preOder_traversal(int midx, int indentation)
{
for (map<string, int>::iterator i=m[midx].begin(); i!=m[midx].end(); ++i)
{
for (int i=0; i<indentation; ++i) printf(" ");
printf("%s\n", (i->first).c_str());
preOder_traversal(i->second, indentation+1);
}
}
int main()
{
//freopen("D:\\in.txt", "r", stdin);
//freopen("D:\\out.txt", "w", stdout);
int n, i, j, midx, midx_counter=0;
char str[MAXLEN];
int word_init[MAXWORD];
string current_str;
scanf("%d", &n);
while (n--)
{
scanf("%s", str);
//
word_init[0]=0;
j=1;
for (i=0; str[i]; ++i)
{
if(str[i]=='\\')
{
str[i]=0;
word_init[j++]=i+1;
}
}
midx=0;
for (i=0; i<j; ++i)
{
current_str=str+word_init[i];
if(!m[midx].count(current_str))
{
m[midx][current_str]=(++midx_counter);
}
midx=m[midx][current_str];
}
}
preOder_traversal(0, 0);
return 0;
}
|