๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 479

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver4] 11652๋ฒˆ_์นด๋“œ

๋ฌธ์ œ https://www.acmicpc.net/problem/11652 11652๋ฒˆ: ์นด๋“œ ์ค€๊ทœ๋Š” ์ˆซ์ž ์นด๋“œ N์žฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ˆซ์ž ์นด๋“œ์—๋Š” ์ •์ˆ˜๊ฐ€ ํ•˜๋‚˜ ์ ํ˜€์žˆ๋Š”๋ฐ, ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -262๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 262๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ์ค€๊ทœ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์นด๋“œ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์ด ๊ฐ€์ง€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 11652๋ฒˆ ๋ฌธ์ œ - ์นด๋“œ n = int(input()) d = {} for i in range(n): card = int(input()) if card in d: d[card] += 1 else: d[card] = 1 result = sorted(d.items(), key = lambda x: (-x[1], x[0])) print(result[0][0]) ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉ..

โฌ› [Programmers] [Python] [Level1] ์†Œ์ˆ˜ ์ฐพ๊ธฐ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/12921 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด def solution(n): num=set(range(2,n+1)) for i in range(2,n+1): if i in num: num-=set(range(2*i,n+1,i)) return len(num) ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด๋ฅผ ์ด์šฉํ•œ ํ’€์ด

โฌ› [Programmers] [Python] [Level1] ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ฐ™์€ ๊ธ€์ž

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/142086 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ฐ™์€ ๊ธ€์ž def solution(s): answer = [] d = dict() for i in range(len(s)): if s[i] not in d: answer.append(-1) else: answer.append(i-d[s[i]]) d[s[i]] = i return answer print(solution("banana"))

โฌ› [Programmers] [Python] [Level1] ํ‘ธ๋“œ ํŒŒ์ดํŠธ ๋Œ€ํšŒ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/134240 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ํ‘ธ๋“œ ํŒŒ์ดํŠธ ๋Œ€ํšŒ def solution(food): answer = '' res = '' for i in range(1, len(food)): if food[i] >= 2: res += (food[i]//2)*str(i) answer = res + str(0) + res[::-1] return answer print(solution([1,3,4,6]))

โฌ› [Programmers] [Python] [Level1] ์‚ผ์ด์‚ฌ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/131705 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ์‚ผ์ด์‚ฌ def solution(number): tot = 0 def dfs(i, depth, sum_num): nonlocal tot if depth == 3 and sum_num == 0: tot += 1 return if i == len(number): return if depth < 3: dfs(i+1, depth+1, sum_num + number[i..

โฌ› [Programmers] [Python] [Level1] ์ด์ƒํ•œ ๋ฌธ์ž ๋งŒ๋“ค๊ธฐ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/12930 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ์ด์ƒํ•œ ๋ฌธ์ž ๋งŒ๋“ค๊ธฐ def solution(s): answer = '' idx = 0 for i in range(len(s)): if s[i] == ' ': answer += ' ' idx = 0 else: if idx % 2 == 0: answer += s[i].upper() idx += 1 else: answer += s[i].lower() idx += 1..

โฌ› [Programmers] [Python] [Level1] ๋ฌธ์ž์—ด ๋‚ด ๋งˆ์Œ๋Œ€๋กœ ์ •๋ ฌํ•˜๊ธฐ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/12915 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ๋ฌธ์ž์—ด ๋‚ด ๋งˆ์Œ๋Œ€๋กœ ์ •๋ ฌํ•˜๊ธฐ def solution(strings, n): return sorted(strings, key = lambda x: (x[n], x)) print(solution(["abce", "abcd", "cdx"], 2)) print(solution(["sun", "bed", "car"], 1)) ๋งจ ์ฒ˜์Œ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ์„ ๋•Œ sorted(st..

โฌ› [Programmers] [Python] [Level2] ์ฃผ์‹๊ฐ€๊ฒฉ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/42584 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์ฃผ์‹ ๊ฐ€๊ฒฉ from collections import deque def solution(prices): queue = deque(prices) answer = [] while queue: price = queue.popleft() sec = 0 for q in queue: sec += 1 if price > q: break answer.append(sec) r..

โฌ› [Programmers] [Python] [Level2] ํ• ์ธ ํ–‰์‚ฌ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/131127 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ํ• ์ธ ํ–‰์‚ฌ from collections import Counter def solution(want, number, discount): answer = 0 d = dict() for i in range(len(want)): d[want[i]] = number[i] #num = sum(number) # ์–ด์ฐจํ”ผ ์ตœ๋Œ€ 10์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด ๊ตฌํ• ํ•„์š”์—†์ด 10์œผ๋กœ ๋‘ฌ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver5] 11004๋ฒˆ_K๋ฒˆ์งธ ์ˆ˜

๋ฌธ์ œ https://www.acmicpc.net/problem/11004 11004๋ฒˆ: K๋ฒˆ์งธ ์ˆ˜ ์ˆ˜ N๊ฐœ A1, A2, ..., AN์ด ์ฃผ์–ด์ง„๋‹ค. A๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ–ˆ์„ ๋•Œ, ์•ž์—์„œ๋ถ€ํ„ฐ K๋ฒˆ์งธ ์žˆ๋Š” ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 11004๋ฒˆ ๋ฌธ์ œ - K๋ฒˆ์งธ ์ˆ˜ import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() print(a[k-1]) ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ ํฌ๊ธฐ ๋•Œ๋ฌธ์— ๋ณ‘ํ•ฉ์ •๋ ฌ๋กœ ํ’€์–ด์•ผ ํ•œ๋‹ค๊ณ  ํ–ˆ๋Š”๋ฐ ๋‚˜๋Š” ์ผ€์ด์Šค๋ฅผ ํ†ต๊ณผํ•˜์˜€๋‹ค. ๋ณ‘ํ•ฉ์ •๋ ฌ์€ ๋‹ค์Œ ๋ฒˆ์— ๋‹ค๋ฃจ๋„๋ก ํ•ด์•ผ๊ฒ ๋‹ค.