Skip to content

Commit

Permalink
2024-03-16
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Mar 16, 2024
1 parent 44fc5a3 commit ed9e5aa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
| 39์ฐจ์‹œ | 2023.02.18 | DP | <a href="https://www.acmicpc.net/problem/7579">์•ฑ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
| 40์ฐจ์‹œ | 2023.02.21 | DP | <a href="https://www.acmicpc.net/problem/31413">์ž…๋Œ€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
| 41์ฐจ์‹œ | 2023.03.04 | DP | <a href="https://www.acmicpc.net/problem/2240">์ž๋‘๋‚˜๋ฌด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
| 45์ฐจ์‹œ | 2023.03.16 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/31413">ํŠธ๋ผ์ด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

class Node():
def __init__(self, key):
self.key = key
self.children = {}

class Tries():
def __init__(self):
self.head = Node(None)

def insert(self, path):
now = self.head
directories = path.split("\\")

for directory in directories:
if directory not in now.children:
now.children[directory] = Node(directory)

now = now.children[directory]

def dfs(self, now : Node, depth):
if now.key is not None:
for _ in range(depth):
print(" ", end="")
print(now.key)

now_children = list(now.children.keys())
now_children.sort()

for child in now_children:
self.dfs(now.children[child], depth+1)

def display_all(self):
now = self.head
self.dfs(now, -1)

tries = Tries()

for _ in range(N):
path = input()
tries.insert(path)

tries.display_all()

0 comments on commit ed9e5aa

Please sign in to comment.