백준 문풀
[Python] 그리디-1213. 팰린드롬 만들기 (실3)
브로코딩
2023. 7. 28. 21:48
https://www.acmicpc.net/problem/1213
1213번: 팰린드롬 만들기
첫째 줄에 문제의 정답을 출력한다. 만약 불가능할 때는 "I'm Sorry Hansoo"를 출력한다. 정답이 여러 개일 경우에는 사전순으로 앞서는 것을 출력한다.
www.acmicpc.net
#개수가 홀수인 알파벳은 단 하나여야 함.
import collections
string = input()
str_list=[]
for i in string:
str_list.append(i)
count_list = collections.Counter(str_list).most_common()
count_list.sort()
flag=0
mid=''
result=''
for i in count_list:
if i[1]%2 !=0:
if flag==1:
flag=2
break
mid=i[0]
flag=1
result+= i[0]*(i[1]//2)
if flag==2:
print('I\'m Sorry Hansoo')
else:
result= result + mid +result[::-1]
print(result)