Koala - 15기/기초 알고리즘 스터디

[백준/Python] 5218 : 알파벳 거리

sori_lee 2024. 7. 21. 22:08

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

문제

풀이

t = int(input())
for i in range(t):
    a, b = input().split()

    ans = []
    for j in range(len(a)):
        x = ord(a[j]) - 64
        y = ord(b[j]) - 64
        if y >= x: z = y - x
        else: z = y + 26 - x
        ans.append(z)
    print('Distances: {}'.format(' '.join(map(str, ans))))
  1. 입력으로 테스트 케이스의 수를 입력 받는다. 
  2. 두 개의 문자열을 입력 받는다.
  3. 대응되는 문자들의 거리를 계산해서 리스트에 저장한다.