본문 바로가기
python-algorithm

백준 14626 ISBN

by 무적김두칠 2022. 11. 24.

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

 

14626번: ISBN

ISBN(International Standard Book Number)은 전 세계 모든 도서에 부여된 고유번호로, 국제 표준 도서번호이다. ISBN에는 국가명, 발행자 등의 정보가 담겨 있으며 13자리의 숫자로 표시된다. 그중 마지막 숫

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def sol(isbn):
    check_sum = 0
    answer = 0
    for i in range(12):
        if i%2 ==0 :
            multiple = 1
        else:
            multiple = 3
        if isbn[i].isnumeric():
            check_sum+=int(isbn[i])*multiple
        else:
            star_multiple = multiple
    m = int(isbn[-1])
    for star in range(10):
        if (m+check_sum+ star*star_multiple)%10 == 0:
            answer = star
    return answer
if __name__ == '__main__':
    isbn = input()
    print(sol(isbn))
 
cs

modular 연산은 분배법칙이 안돼니까 전체 합을 가지고 반복문 쓰시면 됩니다.

Modular operation is not distributive, so you can use loop with the total sum(check_sum).

반응형

'python-algorithm' 카테고리의 다른 글

백준 9047 6174  (0) 2022.11.25
백준 25703 포인터 공부  (0) 2022.11.24
백준 25932 Find the Twins  (0) 2022.11.16
백준 11121 Communication Channels  (0) 2022.11.15
백준 8718 Bałwanek  (0) 2022.11.15

댓글