๊ณต๋ถ€/๋ฐฑ์ค€ (Baekjoon)

[๋ฐฑ์ค€/ํŒŒ์ด์ฌ] 11720๋ฒˆ: ์ˆซ์ž์˜ ํ•ฉ

eunjuu 2023. 11. 9. 12:58
728x90

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

N๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๊ณต๋ฐฑ ์—†์ด ์“ฐ์—ฌ์žˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํ•ฉํ•ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๐Ÿ“Ž https://www.acmicpc.net/problem/11720

 

11720๋ฒˆ: ์ˆซ์ž์˜ ํ•ฉ

์ฒซ์งธ ์ค„์— ์ˆซ์ž์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์— ์ˆซ์ž N๊ฐœ๊ฐ€ ๊ณต๋ฐฑ์—†์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ˆซ์ž์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์— ์ˆซ์ž N๊ฐœ๊ฐ€ ๊ณต๋ฐฑ์—†์ด ์ฃผ์–ด์ง„๋‹ค.

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ถœ๋ ฅ

์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ์ˆซ์ž N๊ฐœ์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์˜ˆ์ œ


๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ฝ”๋“œ

N = int(input())
numbers = input()

num_list = list(map(int, numbers))
total = sum(num_list)

print(total)

 

๊ฐ„๋‹จํ•œ ์ฝ”๋“œ๋‹ค! 

 

โฌ‡๏ธ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด๋ณด์ž.

 

N = int(input())

 

์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ˆซ์ž์˜ ๊ฐœ์ˆ˜ N์„ ์ž…๋ ฅ๋ฐ›์Šต๋‹ˆ๋‹ค. input() ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ž…๋ ฅ์„ ๋ฐ›๊ณ , int() ํ•จ์ˆ˜๋กœ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ๋ณ€์ˆ˜ N์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

 

numbers = input()

 

์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ N๊ฐœ์˜ ์ˆซ์ž๋ฅผ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ์ž…๋ ฅ๋ฐ›์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๋ณ€์ˆ˜ numbers์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

 

# ์ž…๋ ฅ๋ฐ›์€ ์ˆซ์ž๋ฅผ ๊ฐ๊ฐ์˜ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅ
num_list = list(map(int, numbers))

 

numbers ๋ฌธ์ž์—ด์„ ๊ฐ ์ˆซ์ž๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. map(int, numbers)๋Š” numbers์˜ ๊ฐ ๋ฌธ์ž๋ฅผ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๋Š”๋ฐ, list() ํ•จ์ˆ˜๋กœ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

 

# ๋ฆฌ์ŠคํŠธ์˜ ํ•ฉ์„ ๊ณ„์‚ฐ
total = sum(num_list)

print(total)

 

๋ฆฌ์ŠคํŠธ num_list์˜ ํ•ฉ์„ ๊ณ„์‚ฐํ•˜์—ฌ ๋ณ€์ˆ˜ total์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. sum() ํ•จ์ˆ˜๋Š” ๋ฆฌ์ŠคํŠธ์˜ ๋ชจ๋“  ์š”์†Œ๋ฅผ ๋”ํ•ด์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  total์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 


๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ •๋‹ต ์ œ์ถœ

 

728x90