(Python) 1213 팰린드롬 만들기

쿠후·2022년 6월 11일
0

문자열

목록 보기
1/1

링크텍스트

import sys
from collections import Counter

S = sys.stdin.readline().rstrip()
l = list(S)
l.sort()
check = Counter(l)
flag = False
cnt = 0
center = ""
for i in check:
    if check[i] % 2 != 0:
        cnt += 1
        center += i
        l.remove(i)

    if cnt > 1:
        flag = True
        break

if flag :
    print("I'm Sorry Hansoo")

else:
    res = ""

    for i in range(0, len(l), 2):
        res += l[i]
    print(res + center + res[::-1])

    
profile
아직 초짜 개발자인 군인

0개의 댓글