https://www.acmicpc.net/problem/14626
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 |
댓글