1067. Disk Tree(字符串)

1067

破题啊  写完发现理解错题意了 子目录下会有跟之前重名的 

把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<map>
 7 #include<string>
 8 #include<vector>
 9 using namespace std;
10 vector<string>q[510];
11 char sx[510][82][11];
12 struct node
13 {
14     char c[82];
15 }s[510];
16 int o[510];
17 bool cmp(node a,node b)
18 {
19     return strcmp(a.c,b.c)<0;
20 }
21 int main()
22 {
23     int n,i,j,k;
24     char c[11];
25     scanf("%d%*c",&n);
26     for(i = 1; i <= n ; i++)
27     {
28         gets(s[i].c);
29         k = strlen(s[i].c);
30         for(j = 0 ; j < k ; j++)
31         if(s[i].c[j]==92)
32         s[i].c[j] = 1;
33     }
34     sort(s+1,s+n+1,cmp);
35     for(i = 1; i <= n ; i++)
36     {
37         int g = 0;
38         k = strlen(s[i].c);
39         for(j = 0 ; j < k  ;j++)
40         {
41             if(s[i].c[j]!=1)
42             c[g++] = s[i].c[j];
43             else
44             {
45                 c[g] = '';
46                 o[i]++;
47                 strcpy(sx[i][o[i]],c);
48                 g = 0;
49             }
50         }
51         if(g)
52         {
53             c[g] = '';
54             o[i]++;
55             strcpy(sx[i][o[i]],c);
56         }
57     }
58     k = 0;
59     for(i = 1; i <= o[1] ; i++)
60     {
61         for(j = 1 ; j <= k ; j++)
62         printf(" ");
63         printf("%s
",sx[1][i]);
64         k++;
65     }
66     for(i = 2; i <= n ; i++)
67     {
68         int f = 1;k=0;
69         for(j = 1 ; j <= o[i]; j++)
70         {
71             if(!f||o[i-1]<j)
72             {
73                 for(int g = 1 ; g <= k ; g++)
74                 printf(" ");
75                 printf("%s
",sx[i][j]);
76             }
77             else
78             if(strcmp(sx[i][j],sx[i-1][j])!=0)
79             {
80                 for(int g = 1 ; g <= k ; g++)
81                 printf(" ");
82                 printf("%s
",sx[i][j]);
83                 f = 0 ;
84             }
85             k++;
86         }
87     }
88     return 0;
89 }
View Code
原文地址:https://www.cnblogs.com/shangyu/p/3349575.html