๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

4๏ธโƒฃ Python56

[Python Algorithm] Q-์ธ๋ฑ์Šค BOJ #13333 ๋ฌธ์ œ https://www.acmicpc.net/problem/13333 13333๋ฒˆ: Q-์ธ๋ฑ์Šค ICPC ๋Œ€ํ•™์˜ ๋ชจ๋“  ๋ฐ•์‚ฌ๊ณผ์ • ํ•™์ƒ์€ ์ž์‹ ์ด ๋ฐœํ‘œํ•œ ๋…ผ๋ฌธ๊ณผ ๊ทธ ๋…ผ๋ฌธ๋“ค์˜ ์ธ์šฉํšŸ์ˆ˜๋ฅผ ๊ณ ๋ คํ•œ ํ•™์œ„ ์ทจ๋“ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด, ICPC ๋Œ€ํ•™์€ q-์ธ๋ฑ์Šค๋ผ๋Š” ๊ฐ’์„ ์ •์˜ํ–ˆ๋‹ค. ์ด ์ธ๋ฑ์Šค๋Š” ๋…ผ๋ฌธ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) nums = list(map(int, input().split())) nums.sort() m = nums[-1] q = 0 for i in reversed(range(1, m)): tmp = list(filter(lambda x: x >= i, nums)) if len(tmp) >= i: q = i break print(q) ๐Ÿ‘‰ ์ •๋ ฌ ๋ฌธ.. 2022. 2. 10.
[Python Algorithm] ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ BOJ #2579 ๋ฌธ์ œ https://www.acmicpc.net/problem/2579 2579๋ฒˆ: ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ ๊ฒŒ์ž„์€ ๊ณ„๋‹จ ์•„๋ž˜ ์‹œ์ž‘์ ๋ถ€ํ„ฐ ๊ณ„๋‹จ ๊ผญ๋Œ€๊ธฐ์— ์œ„์น˜ํ•œ ๋„์ฐฉ์ ๊นŒ์ง€ ๊ฐ€๋Š” ๊ฒŒ์ž„์ด๋‹ค. ๊ณผ ๊ฐ™์ด ๊ฐ๊ฐ์˜ ๊ณ„๋‹จ์—๋Š” ์ผ์ •ํ•œ ์ ์ˆ˜๊ฐ€ ์“ฐ์—ฌ ์žˆ๋Š”๋ฐ ๊ณ„๋‹จ์„ ๋ฐŸ์œผ๋ฉด ๊ทธ ๊ณ„๋‹จ์— ์“ฐ์—ฌ ์žˆ๋Š” ์  www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys n = int(sys.stdin.readline()) a = [0]*n # ํ˜„์žฌ ๊ณ„๋‹จ ๋ฐŸ๊ณ , ์ง์ „ ๊ณ„๋‹จ ๋ฐŸ์•˜๋‹ค๊ณ  ํ•  ๋•Œ b = [0]*n # ํ˜„์žฌ ๊ณ„๋‹จ ๋ฐŸ๊ณ , ์ง์ „ ๊ณ„๋‹จ ๋ฐŸ์ง€ ์•Š์•˜๋‹ค๊ณ  ํ•  ๋•Œ for i in range(n): now = int(sys.stdin.readline()) if i == 0: a[i] = now b[i] = now elif i == 1: a[i].. 2022. 2. 4.
[Python Algorithm] ๋•…๋”ฐ๋จน๊ธฐ Programmers(Lv.2) ๋ฌธ์ œ https://programmers.co.kr/learn/courses/30/lessons/12913?language=python3 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋•…๋”ฐ๋จน๊ธฐ ๋•…๋”ฐ๋จน๊ธฐ ๊ฒŒ์ž„์„ ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋•…๋”ฐ๋จน๊ธฐ ๊ฒŒ์ž„์˜ ๋•…(land)์€ ์ด Nํ–‰ 4์—ด๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๋ชจ๋“  ์นธ์—๋Š” ์ ์ˆ˜๊ฐ€ ์“ฐ์—ฌ ์žˆ์Šต๋‹ˆ๋‹ค. 1ํ–‰๋ถ€ํ„ฐ ๋•…์„ ๋ฐŸ์œผ๋ฉฐ ํ•œ ํ–‰์”ฉ ๋‚ด๋ ค์˜ฌ ๋•Œ, ๊ฐ ํ–‰์˜ 4์นธ ์ค‘ ํ•œ ์นธ๋งŒ ๋ฐŸ programmers.co.kr ๋‚ด ๋ฌธ์ œ ํ’€์ด def solution(land): if len(land) == 1: return max(land[0]) else: for i in range(1, len(land)): land[i][0] += max(land[i - 1][1], land[i - 1][2], land[i - 1][3]) lan.. 2022. 2. 4.
[Python Algorithm] N๊ฐœ์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ Programmers(Lv.2) ๋ฌธ์ œ https://programmers.co.kr/learn/courses/30/lessons/12953 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - N๊ฐœ์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ๋‘ ์ˆ˜์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜(Least Common Multiple)๋ž€ ์ž…๋ ฅ๋œ ๋‘ ์ˆ˜์˜ ๋ฐฐ์ˆ˜ ์ค‘ ๊ณตํ†ต์ด ๋˜๋Š” ๊ฐ€์žฅ ์ž‘์€ ์ˆซ์ž๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 2์™€ 7์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋Š” 14๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ •์˜๋ฅผ ํ™•์žฅํ•ด์„œ, n๊ฐœ์˜ ์ˆ˜์˜ ์ตœ์†Œ๊ณต๋ฐฐ programmers.co.kr ๋‚ด ๋ฌธ์ œ ํ’€์ด def solution(arr): if len(arr) == 1: return arr[0] else: for i in range(len(arr) - 1): if arr[i] < arr[i + 1]: a = arr[i] b = arr[i + 1] else: a = arr[i + 1] b = arr[i].. 2022. 2. 4.
[Python Algorithm] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ Programmers(Lv.2) ๋ฌธ์ œ https://programmers.co.kr/learn/courses/30/lessons/12951?language=python3 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ JadenCase๋ž€ ๋ชจ๋“  ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ด๊ณ , ๊ทธ ์™ธ์˜ ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด s๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, s๋ฅผ JadenCase๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์กฐ๊ฑด programmers.co.kr ๋‚ด ๋ฌธ์ œ ํ’€์ด def solution(s): num = '0123456789' answer = '' tmp = '' for i in range(len(s)): if s[i] == ' ': answer += tmp + ' ' tmp = '' else: if tmp == .. 2022. 2. 4.