-
Notifications
You must be signed in to change notification settings - Fork 1
20-dohyeondol1 #78
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
20-dohyeondol1 #78
Conversation
|
@Fnhid |
|
μ λ νμ΄μ¬μ import sys
input = sys.stdin.readline
n = int(input())
words = [input().rstrip() for _ in range(n)]
words.sort()
ans = 0
for i, w in enumerate(words):
if i == n - 1 or not words[i + 1].startswith(w):
ans += 1
print(ans) |
|
μ½λ κΈΈμ΄ μ€νν°λΉ..? |
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ΄μ¬ !! μ μλ startswith λΌλ ν¨μκ° λ΄μ₯λμ΄ μλκ΅°μ..!
if savedWord.startswith(currentWord):savedWordκ° currentWordλ‘ μμνλμ§ κ²μ¬ν΄λΌλ λ»μ λλ€!!
λ§€μ° νΈλ¦¬νκ΅°μ!
νμ΄νμ΄
word_count = int(input())
wordList = [input().strip() for _ in range(word_count)]
wordList.sort(key=lambda word: -len(word))
nonPrefixWords = []
for current_Word in wordList:
is_prefix = False
for savedWord in nonPrefixWords:
if savedWord.startswith(current_Word):
is_prefix = True
break
if not is_prefix:
nonPrefixWords.append(current_Word)
print(len(nonPrefixWords))
π λ¬Έμ λ§ν¬
βοΈ μμλ μκ°
20m
β¨ μλ μ½λ
μμ¦ λμ΄λκ° μλ PRμ΄ κ½€ μ¬λΌμμ λμ΄λ μν...μ°¨μμμ μ‘°κΈ μ¬μ΄ λ¬Έμ λ₯Ό κ°μ Έμμ΅λλ€. λ무 μ¬μ΄κ°..?
μ νμ΄ λ§κ³ λ λ€λ₯Έ νμ΄κ° λ§μ보μ¬μ μ¬λ¬λΆμ μ΄λ»κ² μ κ·Όνμ€μ§ κΆκΈν λ§μμ κ°μ Έμ λ΄€μ΅λλ€.
μλ μ½λ
μ¬λ¬ λ¨μ΄κ° μ£Όμ΄μ‘μ λ, λ€λ₯Έ λ¨μ΄μ μ λμ΄κ° λμ§ μλ μ§ν©μ μ΅λ ν¬κΈ°λ₯Ό ꡬνλ λ¬Έμ μ λλ€.
μ΄λ μ λ ¬μ μ¬μ©νλ©΄ κ°λ¨νκ² ν΄κ²°ν μ μμ΅λλ€.
λ§μ½ ν λ¨μ΄μ μ λμ΄κ° λλ λ¨μ΄κ° μλ€λ©΄,
ν΄λΉ λ¨μ΄λ μ¬μ μ μ λ ¬ μ νμ μ λμ΄λ₯Ό ν¬ν¨νλ λ¨μ΄ μμ μμΉνκ² λ©λλ€.
μμ μ λ ₯ 1μ μμλ‘ λ€μ΄λ³΄κ² μ΅λλ€.
μ¬μ μμΌλ‘ μ λ ¬ μ,
helloμ μ λμ΄κ° λλhλhelloμ λ°λ‘ μμ μμΉνλ κ²μ νμΈν μ μμ΅λλ€.runκ³Όrunningλ λ§μ°¬κ°μ§μ£ .μ΄ κ²½μ°, λ°λ³΅λ¬Έμ μ΄μ©ν λΈλ£¨νΈν¬μ€ νμμ ν΅ν΄ ν΄κ²°ν μ μμ΅λλ€.
λ€μ μΈλ±μ€μ λ¨μ΄μμ νμ¬ μΈλ±μ€μ λ¨μ΄ κΈΈμ΄λ§νΌ μλΌλΈ λ¬Έμμ΄μ΄ νμ¬ λ¨μ΄μ κ°λ€λ©΄,
μ 체 λ¨μ΄ κ°μμμ 1μ λΉΌλ λ°©μμΌλ‘ νμ΄ν μ μμ΅λλ€.
μ΄λ μ μΈνλ λ¨μ΄λ μ λμ΄κ° λ μ μλ λ¨μ΄κ° λ©λλ€.
μμ μμ μ λ ₯ 1μμ νμΈν
hλ,helloμ μ λμ΄κ° λ μλ μμ§λ§hiμ μ λμ΄κ° λ μλ μκΈ° λλ¬Έμ΄μ£΅.κ²°κ³Όμ μΌλ‘ λΈλ£¨νΈν¬μ€λ₯Ό μ΄μ©ν΄ μ 체 λ¨μ΄ κ°μμμ μ λμ΄κ° λ μ μλ λ¨μ΄λ€λ§ μ μΈνλ©΄ ν΄κ²°ν μ μλ λ¬Έμ μ λλ€.
π μλ‘κ² μκ²λ λ΄μ©