๊ด€๋ฆฌ ๋ฉ”๋‰ด

C-log

๐Ÿ’ก5597๋ฒˆ ๋ณธ๋ฌธ

๐Ÿง Algorithm/Baekjoon๐Ÿ’ก

๐Ÿ’ก5597๋ฒˆ

4:Bee 2023. 12. 29. 17:38
728x90

์ด์ „์— ๋ฌธ์ œ๋ฅผ ํ’€์ง€ ๋ชปํ–ˆ๋˜ ๊ตฌํ˜„ ๋ฌธ์ œ์ด๋‹ค. ์šฐ์„  ์ œ์ถœํ•œ ํ•™์ƒ๋“ค์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์ด๋ฅผ ๊ธฐ์ค€์œผ๋กœ 1~30๊นŒ์ง€์˜ ๋ช…๋‹จ์„ ๊ธฐ์ค€์œผ๋กœ for๋ฌธ์„ ๋Œ๋ ค์„œ ๋ช…๋‹จ์— ๊ฐ’์ด ์—†๋Š” ์•„์ด๋“ค์„ ๋”ฐ๋กœ exc list ๋ณ€์ˆ˜์— ๋‹ด์•„๋‘”๋‹ค. ๋‹ด์•„๋‘” exc์— ๋ถˆํ•„์š”ํ•œ ์š”์†Œ๋“ค์„ set์œผ๋กœ ์ œ์™ธํ•˜๊ณ  ๋‹ค์‹œ list๋กœ ๋ณ€ํ™˜ ํ•œ๋’ค sort๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ž‘์€ ๊ฐ’์—์„œ ๋†’์€ ๊ฐ’์œผ๋กœ ์ •๋ ฌํ•ด์ค€๋‹ค.

N = []
for _ in range(28):
    N.append(input())
exc = []

for i in range(1, 31):
    for ii in range(len(N)):
        if str(i) not in N:
            exc.append(i)
lst = list(set(exc))

lst.sort()
for i in range(len(lst)):
    print(lst[i])
# print(set(exc))
 
2
8

์ด์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ–ˆ๋‹ค ์—ฌ๊ธฐ์„œ ์ด์ƒํ•œ ์ ์€ ๋‘๋ฒˆ์งธ for๋ฌธ์ด ์žˆ์–ด์•ผํ•  ์ด์œ ๊ฐ€ ํ•ฉ๋‹นํ•˜์ง€ ์•Š๋‹ค ๋”ฐ๋ผ์„œ ์œ„์˜ ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.  for๋ฌธ์„ ์‚ฌ์šฉํ•  ๋•Œ ์Šต๊ด€์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ฐ™๋‹ค. ์ด๋ฅผ ์ข€๋” ์œ ์˜ํ•˜๋ฉฐ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์ข‹์„ ๋“ฏํ•˜๋‹ค.

N = []
for _ in range(28):
    N.append(input())
exc = []

for i in range(1, 31):  # ํ•™์ƒ ์ˆ˜ 30
    # for ii in range(len(N)):  # ์ œ์ถœ ํ•™์ƒ 28
    if str(i) not in N:
        exc.append(i)
 
for i in range(len(exc)):
    print(exc[i])

์ด๋ณด๋‹ค ๋” ๋‹จ์ˆœํ•˜๊ณ  ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค .์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด์ž.


students = [i for i in range(1,31)]

for _ in range(28):
    applied = int(input())
    students.remove(applied) #์†Œ๊ฑฐ

print(min(students))
print(max(students))

removeํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด ์ฝ”๋“œ๋Š” ํ•™์ƒ ๋ช…๋‹จ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. for๋ฌธ์„ ์ง์ ‘ list์„ ์–ธ๋ฌธ ๋ถ€๋ถ„์— ์ง์ ‘์ ์œผ๋กœ ๊ธฐ์ž…ํ–ˆ๋‹ค. ๋งˆ์ง€๋ง‰์œผ๋กœ ์ž‘์€ ์ˆ˜์™€ ํฐ ์ˆ˜๋ฅผ min๊ณผ max๋ฅผ ํ†ตํ•ด์„œ printํ–ˆ๋‹ค.

728x90
Comments