Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

Star_project

2. 자료구조와 알고리즘 입문 6.자릿수의 합 본문

코딩테스트/Python

2. 자료구조와 알고리즘 입문 6.자릿수의 합

star빛 2022. 7. 11. 20:10

 

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