-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path123.cpp
More file actions
94 lines (93 loc) · 2.37 KB
/
123.cpp
File metadata and controls
94 lines (93 loc) · 2.37 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
if (n == 0)
break;
string a[1000]; // string类型的数组,里面每个数组元素都是一个字符串
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
sort(a, a + n);
int k = 0;
for (int i = 0; i < a[0].size(); ++i)
{
if (a[0][i] == '\\')
{
if (i < a[0].size() - 1)
{
cout << endl;
k++;
for (int j = 0; j < k; ++j)
{
cout << " ";
}
}
}
else
{
cout << a[0][i];
}
}
cout << endl;
for (int i = 1; i < n; ++i)
{
int k = 0;
int j;
int flag = false;
for (j = 0; j < a[i].size(); ++j)
{
if (a[i - 1][j] == a[i][j])
{
if (a[i][j] == '\\')
{
k++;
flag = true;
}
}
else
{
break;
}
} // 找与上一个字符串不同的位置
for (; j < a[i].size(); ++j)
{
if (flag)
{
// cout << endl;
for (int l = 0; l < k; ++l)
{
cout << " ";
}
flag = false;
}
if (a[i][j] == '\\')
{
if (j < a[i].size() - 1)
{
cout << endl;
k++;
for (int l = 0; l < k; ++l)
{
cout << " ";
}
}
}
else
{
cout << a[i][j];
}
}
cout << endl;
}
cout << endl;
}
}