본문 바로가기

Python(알고리즘,문제풀이)/BOJ (Bronze V)

2475번 / 검증수

728x90

📚문제

출처 : 백준 / 2475번 (https://www.acmicpc.net/problem/2475)

 

📝풀이

# 2475번 검증수
uniq_num = list(map(int,input().split()))
uniq_num_list = []

for i in uniq_num:
    uniq_num_list.append(i**2)
print(sum(uniq_num_list)%10)

 

이제 이 정도는 얼추 풀리는 것 같다.

풀고나서 다른 풀이도 확인

 

# 다른풀이
result = 0
for i in list(map(int,input().split())): # 변수할당하지 않고 바로 for문에 넣기
    result += i**2
print(result%10)

 

굳이 리스트를 생성할 필요없이

result라는 변수에 for 문을 돌며 계속 값을 더해주면 된다.

그리고 최종적으로 나누기만 하면 끝

 

더 간단하게

print(sum([i**2 for i in list(map(int, input().split()))])%10)

 

참고 링크 :  https://jinho-study.tistory.com/314

728x90

'Python(알고리즘,문제풀이) > BOJ (Bronze V)' 카테고리의 다른 글

10757번 / 큰 수 A+B  (0) 2023.07.18
10699번 / 오늘 날짜  (0) 2023.07.18
2372번 / Livestock Count  (0) 2023.07.11
1809번 / Moo  (0) 2023.07.10
2563번 / 색종이  (0) 2023.07.08