diff --git "a/zinnnn37/202512/4 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" "b/zinnnn37/202512/4 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" new file mode 100644 index 00000000..7de74e72 --- /dev/null +++ "b/zinnnn37/202512/4 BOJ G3 \353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.md" @@ -0,0 +1,80 @@ +```java +import java.io.*; +import java.util.Map; +import java.util.TreeMap; + +public class BJ_7432_디스크_트리 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + + private static int N; + private static Trie trie; + private static String[] words; + + private static class TrieNode { + boolean isEnd; + Map children; + + TrieNode() { + children = new TreeMap<>(); + isEnd = false; + } + + } + + private static class Trie { + TrieNode root; + + Trie() { + root = new TrieNode(); + } + + public void insert(String[] words) { + TrieNode cur = root; + + for (String word : words) { + cur.children.putIfAbsent(word, new TrieNode()); + cur = cur.children.get(word); + } + cur.isEnd = true; + } + + public void print(int depth, TrieNode cur) { + for (String word : cur.children.keySet()) { + appendTabs(depth); + sb.append(word).append("\n"); + print(depth + 1, cur.children.get(word)); + } + } + + private void appendTabs(int depth) { + while (depth-- > 0) { + sb.append(" "); + } + } + + } + + public static void main(String[] args) throws IOException { + sol(); + } + + private static void sol() throws IOException { + N = Integer.parseInt(br.readLine()); + trie = new Trie(); + + while (N-- > 0) { + words = br.readLine().split("\\\\"); + trie.insert(words); + } + trie.print(0, trie.root); + bw.write(sb.toString()); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file