๐Ÿ Algorithm

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2851๋ฒˆ: ์Šˆํผ๋งˆ๋ฆฌ์˜ค(Python)

๋ฌธ์ œ 2851๋ฒˆ: ์Šˆํผ ๋งˆ๋ฆฌ์˜ค ์ฒซ์งธ ์ค„์— ๋งˆ๋ฆฌ์˜ค๊ฐ€ ๋ฐ›๋Š” ์ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ 100์— ๊ฐ€๊นŒ์šด ์ˆ˜๊ฐ€ 2๊ฐœ๋ผ๋ฉด (์˜ˆ: 98, 102) ๋งˆ๋ฆฌ์˜ค๋Š” ํฐ ๊ฐ’์„ ์„ ํƒํ•œ๋‹ค. www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ score = [] sum = 0 sum_under = 0 for i in range(10): score.append(int(input())) for i in range(len(score)): sum += score[i] if sum > 100: sum_under = sum - score[i] break; if abs(100-sum) == abs(100-sum_under): print(sum) else: if abs(100-sum) < abs(100-sum_under): print(sum) else : pr..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ(Python)

๋ฌธ์ œ 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ ์ฒซ์งธ ์ค„์— ํ์˜ ํฌ๊ธฐ N๊ณผ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , M์€ N๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ง€๋ฏผ์ด๊ฐ€ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ์œ„์น˜๊ฐ€ www.acmicpc.net ์ œ์ถœ์ฝ”๋“œ N, M = map(int, input().split()) P = list(map(int, input().split())) q = [i for i in range(1, N+1)] cnt = 0 for i in range(M): # ์œ„์น˜ 0๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฐจ์ด๋กœ ์™ผ์ชฝ์œผ๋กœ or ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ํ•  ์ง€๋ฅผ ๊ฒฐ์ • if q.index(P[i]) < len(q)-q.index(P[i]): while True: if q[0] == P[i]: del q[0] brea..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2460๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ 2(Python)

๋ฌธ์ œ 2460๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ 2 ์ตœ๊ทผ์— ๊ฐœ๋ฐœ๋œ ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ๊ฐ€ 1๋ฒˆ์—ญ(์ถœ๋ฐœ์—ญ)๋ถ€ํ„ฐ 10๋ฒˆ์—ญ(์ข…์ฐฉ์—ญ)๊นŒ์ง€ 10๊ฐœ์˜ ์ •์ฐจ์—ญ์ด ์žˆ๋Š” ๋…ธ์„ ์—์„œ ์šดํ–‰๋˜๊ณ  ์žˆ๋‹ค. ์ด ๊ธฐ์ฐจ์—๋Š” ํƒ€๊ฑฐ๋‚˜ ๋‚ด๋ฆฌ๋Š” ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์น˜๊ฐ€ ์žˆ๋‹ค. www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ num = [] left = [0] for i in range(10): num.append(list(map(int, input().split()))) for i in range(1,11): add = num[i-1][1] - num[i-1][0] left.append(left[i-1] + add) print(max(left)) ๋จผ์ €, num ๋ฆฌ์ŠคํŠธ์— 2์ฐจ์› ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ๋ฐ›์•„ append ํ•จ์ˆ˜๋กœ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•œ๋‹ค. add๋Š” ๊ฐ ์—ญ์—์„œ ํƒ„ ์‚ฌ๋žŒ๊ณผ..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 11399๋ฒˆ: ATM(Python)

๋ฌธ์ œ 11399๋ฒˆ: ATM ์ฒซ์งธ ์ค„์— ์‚ฌ๋žŒ์˜ ์ˆ˜ N(1 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๊ฐ ์‚ฌ๋žŒ์ด ๋ˆ์„ ์ธ์ถœํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ Pi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Pi ≤ 1,000) www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ N = int(input()) P = list(map(int, input().split())) total = 0 P.sort() for i in range(N): for j in range(i+1): total += P[j] print(total) ์ด ๋ฌธ์ œ๋Š” ๋จผ์ € ์ž…๋ ฅ๋ฐ›์€ ๊ฐ ์‚ฌ๋žŒ๋“ค์˜ ์ธ์ถœ ์‹œ๊ฐ„์„ ์ž‘์€ ์‹œ๊ฐ„ ๋ถ€ํ„ฐ ์ •๋ ฌ์„ ํ•ด์•ผํ•œ๋‹ค. ๋ฆฌ์ŠคํŠธ์˜ ์ •๋ ฌ์„ ์œ„ํ•ด ๋ฆฌ์ŠคํŠธ์˜ ๋‚ด๋ถ€ ์š”์†Œ๋ฅผ ์ •๋ ฌํ•ด์ฃผ๋Š” sort() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. sort ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— P.s..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 10871๋ฒˆ: X๋ณด๋‹ค ์ž‘์€ ์ˆ˜(Python)

๋ฌธ์ œ 10871๋ฒˆ: X๋ณด๋‹ค ์ž‘์€ ์ˆ˜ ์ฒซ์งธ ์ค„์— N๊ณผ X๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N, X ≤ 10,000) ๋‘˜์งธ ์ค„์— ์ˆ˜์—ด A๋ฅผ ์ด๋ฃจ๋Š” ์ •์ˆ˜ N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” ๋ชจ๋‘ 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net ํ’€์ด ์ด ๋ฌธ์ œ๋Š” for๋ฌธ๊ณผ if๋ฌธ์„ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‚ด๊ฐ€ ํ—ค๋ฉ˜ ๋ถ€๋ถ„์€ ์˜คํžˆ๋ ค *์ž…๋ ฅ๋ฐ›๋Š” ๋ถ€๋ถ„*์ด์—ˆ๋‹ค. ์ฒ˜์Œ ์ œ์ถœํ•œ ์ฝ”๋“œ N, X = input().split() A = [] for i in range(int(N)): a = int(input()) A.append(a) for i in range(len(A)): if A[i] < int(X): print(A[i], end=" ") ์˜ค๋ฅ˜๋Š” ์—†์—ˆ์ง€๋งŒ ๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€ ๋œฌ..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 10950๋ฒˆ (Python)

๋ฌธ์ œ 10950๋ฒˆ: A+B - 3 ๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ํ’€์ด ์ฒ˜์Œ ์ œ์ถœํ•œ ์ฝ”๋“œ T = int(input()) for i in range(T): A = int(input()) B = int(input()) print(A + B) ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ๋ฐ˜๋ณตํ•ด์„œ ๋”ํ•œ ํ›„ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์ด๋‹ˆ๊นŒ ๊ฐ๊ฐ input()์œผ๋กœ ๋ฐ›๊ณ  for๋ฌธ์„ ๋Œ๋ฆฌ๋ฉด ๋˜๊ฒ ๋‹ค ์ƒ๊ฐํ•ด์„œ ์ œ์ถœํ•˜๋‹ˆ ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ(ValueError)๋ผ๊ณ  ๋–ด๋‹ค. ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ์˜ ์ด์œ ๋Š” ๋”ฑํžˆ ์„ค๋ช…๋˜์–ด์žˆ์ง€ ์•Š์•„ ๊ทธ๋ƒฅ ์‹œ๊ฐ„์ด ์˜ค๋ž˜๊ฑธ๋ ธ๋‚˜๋ณด๋‹ค ํ•˜๊ณ  ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋˜ ์ค‘ input()์œผ๋กœ ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒƒ์ด ๋” ๋Š๋ฆฌ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์•˜๋‹ค. ์•Œ์•„๋ณด๋‹ˆ input()์€ ์ž…๋ ฅ ๊ฐ’ ํ•˜๋‚˜ ๋งˆ๋‹ค ๋ฒ„ํผ์— ์ €์žฅํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ๋•Œ..

Dhey
'๐Ÿ Algorithm' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (6 Page)