Notice
Recent Posts
Recent Comments
Link
관리 메뉴

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