-
Notifications
You must be signed in to change notification settings - Fork 5
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
22-Hwangyerin #99
22-Hwangyerin #99
Conversation
λ―μ΅μ μ΄λ¦μ΄ !! |
μ? |
for key, value in count_name.items(): | ||
if value%2==1: | ||
odd += 1 | ||
odd_alphabet = key | ||
|
||
# λ§μ½ νμκ°μΈ μνλ²³μ΄ 2κ° μ΄μμ΄λΌλ©΄ ν°λ¦°λ둬μ λ§λ€ μ μμ | ||
if odd > 1: | ||
print("I'm Sorry Hansoo") | ||
else: | ||
for key, value in count_name.items(): | ||
answer += (key*(value//2)) | ||
print(answer + odd_alphabet + answer[::-1]) |
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.
for-else λ¬Έμ μ¬μ©νμ¬ ν μλ μκ² λ€μ!
for key, value in count_name.items():
if value%2==1:
odd += 1
if odd>1:
print("I'm Sorry Hansoo")
break
odd_alphabet = key
answer += (key*(value//2))
else:
print(answer+odd_alphabet+answer[::-1])
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.
κ·ΈλΌμ~
μμ μ¬λ with νμ.. |
name = input() | ||
|
||
# κ° μνλ²³ κ°μ ꡬνκ³ μ€λ¦μ°¨μμΌλ‘ μ λ ¬ | ||
count_name = dict(sorted(Counter(name).items())) |
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.
1λ
μ μ μ λ μΉ΄μ΄ν°λ₯Ό μΈ μ€ λͺ°λμλ€μ
μ΄λ κ²λ κ°λ¨νκ² μ€μ¬λ²λ¦΄ μ μλ€λ ...
# 1λ
μ μ μ μμ½λ
#[('A', 6), ('V', 6), ('C', 1)] ννλ‘
letters = []
for letter in name_dic:
letters.append((letter,name_dic[letter]))
#μ λ ¬ λ¨Όμ
letters.sort()
for key, value in count_name.items(): | ||
if value%2==1: | ||
odd += 1 | ||
odd_alphabet = key | ||
|
||
# λ§μ½ νμκ°μΈ μνλ²³μ΄ 2κ° μ΄μμ΄λΌλ©΄ ν°λ¦°λ둬μ λ§λ€ μ μμ | ||
if odd > 1: | ||
print("I'm Sorry Hansoo") | ||
else: | ||
for key, value in count_name.items(): | ||
answer += (key*(value//2)) | ||
print(answer + odd_alphabet + answer[::-1]) |
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.
μ λ λ°μͺ½μ λ¨Όμ λ§λ€μ΄μ€λ²λ¦¬κ³ μΆλ ₯ν λ [::-1]
λ₯Ό μ¬μ©νμ¬ ν©μ³μ£Όμμλλ°
μμ oddλ₯Ό ν¨κ» νλ¨ν΄μ€λ²λ¦¬λ κ²λ μ’κ² λ€μ ~
μ’μ μ½λ λ λ°°μκ°λλ€ :) κ΅Ώκ΅Ώ bbb
for letter in letters:
# κ°μκ° νμμΈ μνλ²³μ΄ μ¬λ¬κ°λ©΄ break
if letter[1]%2 != 0:
break_cnt += 1
#νμμΈ μνλ²³μ΄ μΌν°μ μ€κ² λ κ²
center += letter[0]
# κ°μκ² 2κ° μ΄μμ΄λ©΄
# λ°μͺ½λ§ μΌλ¨ λ§λ€μ΄μ£Όμ
Palindrome += letter[0]*(letter[1]//2)
if break_cnt > 1:
print("I'm Sorry Hansoo")
else:
print(Palindrome + center + Palindrome[::-1])
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.
μ λ μλ¦°λκ³Ό λΉμ·νκ² μ½λλ₯Ό μ§°λλ°μ! μ μλμ 리뷰 λλΆμ μ μ½λλ₯Ό λ κ°λ
μ±μκ² μ§λ λ°©λ²λ ν°λνμμ΅λλ€π
λ€μ μ°¨μ,,,λ§μΈν¬λννΈ,,,κΈ°λλλκ΅°μ¬,,ννπ
name = input() | ||
|
||
# κ° μνλ²³ κ°μ ꡬνκ³ μ€λ¦μ°¨μμΌλ‘ μ λ ¬ | ||
count_name = dict(sorted(Counter(name).items())) |
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.
μ λ μ μλμ²λΌ μνλ²³ κ°―μλ₯Ό ꡬνκΈ° μν΄ λ°λ³΅λ¬Έμ μ¨μ κ°κ° appendν΄μ€¬λλ° Counterλ₯Ό μ°λ λ°©λ²μ΄ μμλ€μ!
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.
ν°λ¦°λλ‘¬μ΄ λ μ μλ κ²½μ°μΈ, νμ κ°μ μνλ²³μ΄ 2κ° μ΄μμΈ κ²½μ°λ₯Ό ꡬλΆν΄λκ³ μ½λλ₯Ό μ§ κ² μΈμμ μ
λλ€. 첨λΆν΄μ£Όμ μ¬μ§λ μ λ§ ν° λμμ΄ λμμ΅λλ€ π€ π
μ΄λ²μ°¨μ prλ μκ³ λ§μΌμ
¨μ΅λλ€ β‘β₯οΈ
π λ¬Έμ λ§ν¬
Baekjoon | ν°λ¦°λ둬 λ§λ€κΈ°
λ¬Έμ
μνμμ μλ¬ΈλΉμ μλ‘ μ¬λνλ μ¬μ΄μ΄λ€.
μνμλ μΈμμμ ν°λ¦°λλ‘¬μΈ λ¬Έμμ΄μ λ무 μ’μνκΈ° λλ¬Έμ, λμ λ°±μΌμ κΈ°λ ν΄μ μλ¬ΈλΉμ ν°λ¦°λ둬μ μ λ¬Όν΄μ£Όλ €κ³ νλ€.
μλ¬ΈλΉμ μνμμ μμ΄ μ΄λ¦μΌλ‘ ν°λ¦°λ둬μ λ§λ€λ €κ³ νλλ°, μνμμ μμ΄ μ΄λ¦μ μνλ²³ μμλ₯Ό μ μ ν λ°κΏμ ν°λ¦°λ둬μ λ§λ€λ €κ³ νλ€.
μλ¬ΈλΉμ λμ μνμμ μμ΄ μ΄λ¦μ ν°λ¦°λ둬μΌλ‘ λ°κΎΈλ νλ‘κ·Έλ¨μ μμ±νμμ€.
μ λ ₯
첫째 μ€μ μνμμ μμ΄ μ΄λ¦μ΄ μλ€. μνλ²³ λλ¬Έμλ‘λ§ λ μ΅λ 50κΈμμ΄λ€.
μΆλ ₯
첫째 μ€μ λ¬Έμ μ μ λ΅μ μΆλ ₯νλ€. λ§μ½ λΆκ°λ₯ν λλ "I'm Sorry Hansoo"λ₯Ό μΆλ ₯νλ€. μ λ΅μ΄ μ¬λ¬ κ°μΌ κ²½μ°μλ μ¬μ μμΌλ‘ μμλ κ²μ μΆλ ₯νλ€.
βοΈ μμλ μκ°
40λΆ
β¨ μλ μ½λ
ν°λ¦°λλ‘¬μ΄ μλλ κ²½μ°
ν°λ¦°λλ‘¬μ΄ λλ κ²½μ°
μ¦, ν°λ¦°λλ‘¬μ΄ λ μ μλ μμ΄ μ΄λ¦μΈμ§ μκΈ° μν΄μλ κ° μνλ²³μ κ°μλ₯Ό μμμΌνλ€.
β³ Counter ν¨μ μ¬μ©
μΆλ ₯ 쑰건μ 보면 λ€μκ³Ό κ°μ΄ μ£Όμ΄μ Έ μλ€.
Counter(name).items() ν¨μλ‘ λ§λ€μ΄μ§ 리μ€νΈμ μμλ νν ννλ‘ μνλ²³(key)κ³Ό μνλ²³μ κ°μ(value)λ‘ μ΄λ£¨μ΄μ Έ μλ€.
dict_items([('A', 5), ('B', 4), ('C', 3)])
μ΄ν μ½λμμ κ³μ keyμ valueλ₯Ό μ¬μ©νκΈ° μν΄μλ λμ λλ¦¬λ‘ λ°κΏμ€μΌνλ€.
κ·Έλμ sortedλ‘ μ€λ¦μ°¨μμΌλ‘ μ λ ¬μ ν΄μ€ λ€ λ€μ λμ λλ¦¬λ‘ νμ μ λ°κΏμ£Όμλ€.
μ μ μΈκΈνλ κ²κ³Ό κ°μ΄ λ¬Έμμ΄μ νμκ°μΈ μνλ²³μ κ°μκ° λκ° μ΄μμΌ λμλ ν°λ¦°λλ‘¬μ΄ λ μ μλ€.
key: μνλ²³, value: μνλ²³ κ°μ
λ§μ½ νμκ°μ μνλ²³μ΄ λκ° μ΄μ(odd>1)μ΄λΌλ©΄
I'm Sorry Hansoo μΆλ ₯
νμκ°μ μνλ²³μ΄ μκ±°λ 1κ°λΌλ©΄ λ€μκ³Ό κ°μ΄ μΆλ ₯νλ€.
β² νμκ°μ μνλ²³μ΄ νλμΌ κ²½μ°
μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©
λ§μΈν¬λννΈλ λ€μ μ°¨μμ μ¬λ¦΄ μμ μ λλ€π₯²