[BOJ] 11720: 숫자의 합

🔒 예제

>> 1
>> 1
	
1

>> 5
>> 54321

15

>> 25
>> 7000000000000000000000000

7

>> 11
>> 10987654321

46

🔧 풀이

1. N = int(sys.stdin.readline().rstrip())
2. nums = sys.stdin.readline().rstrip()
3. for문

🔑 답안

import sys

N = int(sys.stdin.readline().rstrip())
nums = sys.stdin.readline().rstrip()

sum = 0
for i in range(len(nums)):
	sum += int(nums[i])
print(sum)

💡 개념

### split
a.split()			# split by " "
a.split("\n")   	# split by "\n"\
a.split("\n", 2)	# split by "\n" 2 times
a.split(sep="\n", maxsplit=2)

좋은 웹페이지 즐겨찾기