From 81e32e1db7e529bda283716e655c5f851c492f35 Mon Sep 17 00:00:00 2001 From: HeeEul Shin <83682424+ShinHeeEul@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:24:52 +0900 Subject: [PATCH] =?UTF-8?q?[20250409]=20BOJ=20/=20G3=20/=20=EA=B0=9C?= =?UTF-8?q?=EB=AF=B8=EA=B5=B4=20/=20=EC=8B=A0=ED=9D=AC=EC=9D=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3 \352\260\234\353\257\270\352\265\264.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "ShinHeeEul/202504/09 BOJ G3 \352\260\234\353\257\270\352\265\264.md" diff --git "a/ShinHeeEul/202504/09 BOJ G3 \352\260\234\353\257\270\352\265\264.md" "b/ShinHeeEul/202504/09 BOJ G3 \352\260\234\353\257\270\352\265\264.md" new file mode 100644 index 00000000..b679d995 --- /dev/null +++ "b/ShinHeeEul/202504/09 BOJ G3 \352\260\234\353\257\270\352\265\264.md" @@ -0,0 +1,77 @@ +```java +import java.util.*; +import java.io.*; + +class Main { + + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + Trie trie = new Trie(); + for(int i = 0; i < N; i++) { + Trie in = trie; + StringTokenizer st = new StringTokenizer(br.readLine()); + int K = Integer.parseInt(st.nextToken()); + for(int j = 0; j < K; j++) { + String s = st.nextToken(); + + // 이미 있을 때? + Trie deep = in.children.get(s); + + if(deep == null) { + in.children.put(s, new Trie()); + deep = in.children.get(s); + } + + in = deep; + } + } + backTracking(trie, 0); + System.out.println(sb); + + } + + public static void backTracking(Trie trie, int depth) { + + String[] arr = trie.children.keySet().toArray(new String[0]); + Arrays.sort(arr); + for(String s : arr) { + for(int i = 0; i < depth; i++) { + sb.append("--"); + } + sb.append(s).append("\n"); + backTracking(trie.children.get(s), depth + 1); + } + } + + static class Trie { + HashMap children = new HashMap<>(); + } + + private static int read() throws Exception { + int c; + int n = 0; + boolean negative = false; + + while ((c = System.in.read()) <= 32) { + if (c == -1) return -1; + } + + if (c == '-') { + negative = true; + c = System.in.read(); + } + + do { + n = n * 10 + (c - '0'); + c = System.in.read(); + } while (c > 32); + + return negative ? -n : n; + } + + +} +```