๐ŸŒฑ → ๐ŸŒณ

[๋ฐฑ์ค€] 10950๋ฒˆ : A+B-3 python ๋ณธ๋ฌธ

Algorithms

[๋ฐฑ์ค€] 10950๋ฒˆ : A+B-3 python

BAY 2022. 7. 7. 16:47
728x90

https://www.acmicpc.net/problem/10950

 

10950๋ฒˆ: A+B - 3

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

 

์ฒ˜์Œ์— ์ž‘์„ฑํ•œ ํ’€์ด :

a=int(input())
dic=[]
for i in range(a):
  x,y=map(int,input().split())
  dic.append(x+y)
for i in dic:
  print(i)

 

dic๋ผ๋Š” list๋ฅผ ์„ ์–ธํ•ด์„œ dic์— x+y ๊ฐ’์„ ๋”ํ•˜๊ณ , 

๋˜ ํ•œ๋ฒˆ์˜ for๋ฌธ์„ ์ด์šฉํ•ด์„œ print ํ•˜๋ ค๊ณ  ํ–ˆ์Œ 

๋Œ์•„๊ฐ€๊ธฐ๋Š” ํ•˜๋Š”๋ฐ 

๋‹ค๋ฅธ ํ’€์ด ์ฐพ์•„๋ณด๋‹ˆ๊นŒ ํ›จ์”ฌ ์‰ฝ๊ณ  ๊ฐ„ํŽธํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ์Œ (์ œ์ผ ์•„๋ž˜์—)

 

 

๊ทผ๋ฐ ๋งˆ์ง€๋ง‰ ์ค„์— ์•„๋ž˜ ์ฒ˜๋Ÿผ ๋„ฃ์œผ๋ฉด ์™œ ์˜ค๋ฅ˜๊ฐ€ ๋œฐ๊นŒ ..!.?

for i in dic:
  print(dic[i])

IndexError: list index out of range ๋ผ๊ณ  ๋œจ๋Š”๋ฐ 

dic[0] ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋‹ˆ๊นŒ ํ•œ ๊ฐœ ๋” printํ•˜๋ ค ํ•ด์„œ ๊ทธ๋Ÿฐ๊ฐ€ ? ํœด 

 

python ๋„ˆ๋ฌด ๊ฒ‰ํ•ฅ๊ธฐ๋กœ ๋ฐฐ์›Œ์„œ 

๋ฌธ๋ฒ•๋„ ์ด๋ฆฌ์ €๋ฆฌ ํ—ท๊ฐˆ๋ฆฌ๊ธฐ๋งŒ ํ•œ ๊ฒƒ ๊ฐ™๋‹ค 

์ฒ˜์Œ์— ๋ฐฐ์šธ ๋•Œ ์ œ๋Œ€๋กœ ๋ฐฐ์› ์–ด์•ผ ํ–ˆ๋Š”๋ฐ 

ํ›„ํšŒ๋ณด๋‹จ ๊ณ  .. (๏ผพ๏ผพ๏ผ›)

์•ž์œผ๋กœ ๊ผผ๊ผผํžˆ ๋ฐฐ์›Œ๋ณด๋„๋ก ๋…ธ๋ ฅํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.. 

 

์‰ฌ์šด ํ’€์ด:

a=int(input())
for i in range(a):
  x,y=map(int, input().split())
  print(x+y)

 

๊ทผ๋ฐ ์ด ํ’€์ด๋Š” 

์ž…๋ ฅ -> ์ถœ๋ ฅ -> ์ž…๋ ฅ -> ์ถœ๋ ฅ ์ด ์ˆœ์„œ๋‹ˆ๊นŒ ํ‹€๋ฆฐ ๊ฑฐ ์•„๋‹Œ๊ฐ€

์ฒ˜์Œ ํ–ˆ๋˜ ํ’€์ด๋Š”

๋‚ด๊ฐ€ ์ •ํ•œ ์ˆซ์ž๋งŒํผ ์ž…๋ ฅ -> ์ถœ๋ ฅ์ด ๊ฐ€๋Šฅํ•œ๋”” 

์ƒ๊ด€์—†๋‚˜? ์ฐธ ๋‚˜ 

 

728x90