-
Notifications
You must be signed in to change notification settings - Fork 6
/
JIHANEOL.java
60 lines (41 loc) · 1.09 KB
/
JIHANEOL.java
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
import java.io.*;
import java.util.*;
public class JIHANEOL {
static BufferedReader br;
static class Node{
Map<String, Node> map = new TreeMap<>();
}
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.valueOf(br.readLine());
String[][] contents = new String[n][];
for(int i=0; i<n; i++) {
contents[i] = br.readLine().split("\\\\");
}
Node rootNood = new Node(); // 루트
for(int i=0; i<n; i++) {
String[] now = contents[i];
Node root = rootNood;
for(String current : now) {
// 있으면
if(root.map.containsKey(current)) {
root = root.map.get(current);
}
// 엾으면
else {
root.map.put(current, new Node());
root = root.map.get(current);
}
}
}
dfs(rootNood, "");
System.out.println(sb.toString());
}
public static void dfs(Node root, String tap) {
for(String now : root.map.keySet()) {
sb.append(tap+now+"\n");
dfs(root.map.get(now), tap+" ");
}
}
}