๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 5597 - ๊ณผ์ œ ์•ˆ ๋‚ด์‹  ๋ถ„..?

by YWTechIT 2021. 4. 26.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 5597 - ๊ณผ์ œ ์•ˆ ๋‚ด์‹  ๋ถ„..?

๋ฐฑ์ค€ 5597 - ๊ณผ์ œ ์•ˆ ๋‚ด์‹  ๋ถ„..?


โšก๏ธ ๋‚˜์˜ ํ’€์ด

๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€์—ˆ๋Š”๋ฐ

 

  1. ์ž…๋ ฅ๊ฐ’์„ list๋กœ ๋งŒ๋“ค์–ด ๋ฐ˜๋ณต๋ฌธ์„ ์„ ์–ธํ•˜๊ณ  ํ•ด๋‹น i๊ฐ€ ์ „์ฒด ๋ฒ”์œ„์ธ students์•ˆ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์—†๋Š” ๊ฐ’๋“ค์„ ์ถœ๋ ฅํ•˜๊ฒŒ ๋งŒ๋“ค์—ˆ๋‹ค.
  2. ์ „์ฒด ๋ฒ”์œ„์™€ ์ž…๋ ฅ๊ฐ’์„ ๋ชจ๋‘ setํ˜•์œผ๋กœ ์„ ์–ธํ•œ๋’ค ์„œ๋กœ ๋นผ์ฃผ๊ณ  sortedํ–ˆ๋‹ค.

 

๋ฌธ์ œ๋ฅผ ์ž์„ธํžˆ ๋ณด๋ฉด ์ œ์ถœํ•˜์ง€ ์•Š์€ ํ•™์ƒ์˜ ์ถœ์„๋ฒˆํ˜ธ ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฒƒ์„ ์ถœ๋ ฅํ•˜๋ผ๊ณ  ๋˜์–ด์žˆ๋Š”๋ฐ, ๋ฌธ์ œ ์˜๋„๋Š” 1๋ฒˆ๋ณด๋‹ค๋Š” 2๋ฒˆ ์ฝ”๋“œ์— ๋” ๊ฐ€๊น๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด sorted๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ž‘์€ ์ˆ˜๋ถ€ํ„ฐ ์ถœ๋ ฅํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

# case 1
students = list(range(1, 31))
report = [int(input()) for i in range(28)]
print('\n'.join(map(str, [i for i in students if i not in report])))

# case 2
students = list(range(1, 31))
report = sorted(int(input()) for i in range(28))
result = set(students) - set(report)
print('\n'.join(map(str, sorted(result))))
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€