Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

45-tgyuuAn #162

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„ ๋ฌธ๋ฒ•์„ ์ฒ˜์Œ๋ด์„œ ๋˜ ์ค์คํ•ด๊ฐ‘๋‹ˆ๋‹น
๊ฐ์ฒด ํƒ€์ž…์„ ๋„˜๊ฒจ์ค„ ๋•Œ๋Š” a :(๊ฐ์ฒด) ๋กœ ์ „๋‹ฌํ•œ๋‹ค ..!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•… ์ด๊ฑด ์‚ฌ์‹ค ์žˆ์œผ๋‚˜ ์—†์œผ๋‚˜ ๊ด€๋ จ์—†๋Š” ๋ฌธ๋ฒ•์ธ๋ฐ,

์ €๋ ‡๊ฒŒ ํƒ€์ž…์„ ๋ช…์‹œํ•ด ์ค„ ๊ฒฝ์šฐ ๋ฉ”์†Œ๋“œ ๋‚ด๋ถ€์—์„œ ํ•ด๋‹น ๊ฐ์ฒด์˜ ํ•จ์ˆ˜๋ฅผ ide์—์„œ ํ˜ธ์ถœํ•ด์ค„ ์ˆ˜ ์žˆ์–ด์š”.

์˜ˆ๋ฅผ๋“ค๋ฉด listํƒ€์ž…์— a๋งŒ ์“ฐ๋ฉด append๊ฐ€ ๋ฆฌ์ŠคํŠธ์— ๋‚˜์˜ค๋Š” ๊ฒƒ ์ฒ˜๋Ÿผ..?

ํŒŒ์ด์ฌ์€ ์ €๋ ‡๊ฒŒ ํƒ€์ž… ๋ช…์‹œํ•ด์ค˜๋„ ๊ฐ•์ œ์„ฑ์ด ์—†์–ด์„œ ์–ด๋–ค ํƒ€์ž…์ด๋˜ ๋„ฃ์–ด์ค„ ์ˆ˜ ์žˆ์–ด์š”!!

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()