From 6567f5dc26c7f80a4057c768f429e54eb16c94eb Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 9 Feb 2025 01:00:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250209]=20BOJ=20/=20=EA=B3=A8=EB=93=9C3=20/?= =?UTF-8?q?=20=EB=94=94=EC=8A=A4=ED=81=AC=20=ED=8A=B8=EB=A6=AC=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\201\254 \355\212\270\353\246\254.md" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "khj20006/202502/09 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" 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