python-algorithm

백준 25915 연세여 사랑한다

무적김두칠 2022. 11. 30. 12:01

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

 

25915번: 연세여 사랑한다

훈규가 비밀번호를 모두 입력하기 위한 이동 거리의 최솟값을 출력한다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
def sol(c, yonsei):
    answer = 0
    yonsei.insert(0,c)
    for i in range(1,len(yonsei)):
        answer+=abs(ord(yonsei[i])-ord(yonsei[i-1]))
 
    return answer
if __name__ == '__main__':
    c =input()
    yonsei = (list('ILOVEYONSEI'))
    print(sol(c,yonsei))
cs
반응형