diff --git "a/khj20006/202502/09 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" "b/khj20006/202502/09 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" new file mode 100644 index 00000000..e4b4bdb0 --- /dev/null +++ "b/khj20006/202502/09 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" @@ -0,0 +1,83 @@ +```java + +import java.util.*; +import java.io.*; + +class Node{ + String name; + TreeMap subs; + Node(String name){ + this.name = name; + subs = new TreeMap(); + } +} + +class Trie{ + Node root; + Trie(){ + root = new Node("ROOT"); + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static Trie trie; + static int N; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + N = Integer.parseInt(br.readLine()); + trie = new Trie(); + + } + + static void solve() throws Exception{ + + while(N-- > 0){ + String line = br.readLine(); + String[] dirs = line.split("\\\\"); + Node cur = trie.root; + for(String dir : dirs){ + if(!cur.subs.containsKey(dir)) cur.subs.put(dir, new Node(dir)); + cur = cur.subs.get(dir); + } + + } + + print(trie.root, -1); + + } + + static void print(Node cur, int dep) throws Exception{ + if(dep >= 0){ + for(int i=0;i