Notice
Recent Posts
Recent Comments
Link
Star_project
2. 자료구조와 알고리즘 입문 6.자릿수의 합 본문
import sys
sys.stdin=open("pythonalgorithm/섹션 2/6. 자릿수의 합/in2.txt")
n=int(input())
a=list(map(int, input().split()))
def digit_sum(x):
sum=0
while x>0:
sum+=x%10
x=x//10
return sum
max=-2147000000
for x in a:
tot=digit_sum(x)
if max<tot:
max=tot
res=x
print(res)
자릿수의 합 구하기
while x>0:
sum+=x%10
x=x//10
'코딩테스트 > Python' 카테고리의 다른 글
[프로그래머스] 자릿수 더하기 (0) | 2022.07.11 |
---|---|
2. 자료구조와 알고리즘 입문 7. 소수(에라토스테네스 체) (0) | 2022.07.11 |
2. 자료구조와 알고리즘 입문 4. 대표값 (0) | 2022.07.11 |
2. 자료구조와 알고리즘 입문 03.K번째 큰 수 (0) | 2022.07.11 |
알파벳 숫자로 변환/바꾸기 in python (0) | 2022.06.09 |