Algorithm/백준

[백준 Python] 1213번 팰린드롬 만들기

얼음새꽃 2023. 7. 14. 19:30
반응형

문제

https://www.acmicpc.net/problem/1213

 

풀이

if __name__ == '__main__':
    english_name = input()
    odd_number_name = ""
    name_dict = {}
    result_name = ""

    english_name = sorted(english_name)
    for string in english_name:
        if string in name_dict:
            name_dict[string] += 1
        else:
            name_dict[string] = 1

    for name in name_dict:
        if name_dict[name] % 2 != 0:
            if odd_number_name == "":
                odd_number_name = name
            else:
                print("I'm Sorry Hansoo")
                exit()

    for name in name_dict:
        for count in range(name_dict[name] // 2):
            result_name += name
        name_dict[name] = int(name_dict[name] / 2)

    result_name = result_name + odd_number_name + result_name[::-1]
    print(result_name)
반응형