๐Ÿ—๏ธ Algorithm 344

โฌ› [Programmers] [Java] [Level1] ์ž๋ฆฟ์ˆ˜ ๋”ํ•˜๊ธฐ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/12931?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด import java.util.*; public class Solution { public int solution(int n) { int answer = 0; while(n > 0){ answer += n%10; n/=10; } return answer; } } String์œผ๋กœ ๋ณ€ํ™˜ ํ›„ ๊ฐ๊ฐ์˜ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋”ํ•ด๋„ ๋˜์ง€๋งŒ ๊ตณ์ด ๋ณ€ํ™˜ํ•˜์ง€ ์•Š๊ณ ๋„ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด..

๐ŸŸฉ [๋ฐฑ์ค€] [Java] [Silver5] 2941๋ฒˆ_ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ

๋ฌธ์ œ https://www.acmicpc.net/problem/2941 2941๋ฒˆ: ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ ์˜ˆ์ „์—๋Š” ์šด์˜์ฒด์ œ์—์„œ ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ์„ ์ž…๋ ฅํ•  ์ˆ˜๊ฐ€ ์—†์—ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ์„ ๋ณ€๊ฒฝํ•ด์„œ ์ž…๋ ฅํ–ˆ๋‹ค. ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ ๋ณ€๊ฒฝ ฤ c= ฤ‡ c- dลพ dz= ฤ‘ d- lj lj nj nj š s= ลพ z= www.acmicpc.net ํ’€์ด import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class ํฌ๋กœ์•„ํ‹ฐ์•„์•ŒํŒŒ๋ฒณ { public static void main(String[] args) throws IOException { BufferedReader br =..

๐ŸŸฉ [๋ฐฑ์ค€] [Java] [Silver5] 1316๋ฒˆ_๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค

๋ฌธ์ œ https://www.acmicpc.net/problem/1316 1316๋ฒˆ: ๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค ๊ทธ๋ฃน ๋‹จ์–ด๋ž€ ๋‹จ์–ด์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด์„œ, ๊ฐ ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋งŒ์„ ๋งํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ccazzzzbb๋Š” c, a, z, b๊ฐ€ ๋ชจ๋‘ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ณ , kin๋„ k, i, n์ด ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ธฐ ๋•Œ www.acmicpc.net ํ’€์ด import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class ๊ทธ๋ฃน๋‹จ์–ด์ฒด์ปค { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); pub..

๐ŸŸฉ [๋ฐฑ์ค€] [Java] [Silver5] 4673๋ฒˆ_์…€ํ”„ ๋„˜๋ฒ„

๋ฌธ์ œ https://www.acmicpc.net/problem/4673 4673๋ฒˆ: ์…€ํ”„ ๋„˜๋ฒ„ ์…€ํ”„ ๋„˜๋ฒ„๋Š” 1949๋…„ ์ธ๋„ ์ˆ˜ํ•™์ž D.R. Kaprekar๊ฐ€ ์ด๋ฆ„ ๋ถ™์˜€๋‹ค. ์–‘์˜ ์ •์ˆ˜ n์— ๋Œ€ํ•ด์„œ d(n)์„ n๊ณผ n์˜ ๊ฐ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋”ํ•˜๋Š” ํ•จ์ˆ˜๋ผ๊ณ  ์ •์˜ํ•˜์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, d(75) = 75+7+5 = 87์ด๋‹ค. ์–‘์˜ ์ •์ˆ˜ n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, www.acmicpc.net ํ’€์ด public class ์…€ํ”„๋„˜๋ฒ„ { public static void main(String[] args) { boolean[] check = new boolean[10001]; for (int i = 1; i < 10001; i++){ int n = d(i); if(n < 10001){ check[n] = true; } } StringB..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 13335๋ฒˆ_ํŠธ๋Ÿญ

๋ฌธ์ œ https://www.acmicpc.net/problem/13335 13335๋ฒˆ: ํŠธ๋Ÿญ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋Š” ํ‘œ์ค€์ž…๋ ฅ์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ž…๋ ฅ์€ ๋‘ ์ค„๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค. ์ž…๋ ฅ์˜ ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ์„ธ ๊ฐœ์˜ ์ •์ˆ˜ n (1 ≤ n ≤ 1,000) , w (1 ≤ w ≤ 100) and L (10 ≤ L ≤ 1,000)์ด ์ฃผ์–ด์ง€๋Š”๋ฐ, n์€ ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋Š” ํŠธ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 13335๋ฒˆ ๋ฌธ์ œ - ํŠธ๋Ÿญ n, w, l = map(int, input().split()) trucks = list(map(int, input().split())) bridge = [0] * w time = 0 while bridge: time += 1 bridge.pop(0) if trucks: if sum(bridge) + t..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 15685๋ฒˆ_๋“œ๋ž˜๊ณค ์ปค๋ธŒ

๋ฌธ์ œ https://www.acmicpc.net/problem/15685 15685๋ฒˆ: ๋“œ๋ž˜๊ณค ์ปค๋ธŒ ์ฒซ์งธ ์ค„์— ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 20)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ์ •๋ณด๋Š” ๋„ค ์ •์ˆ˜ x, y, d, g๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. x์™€ y๋Š” ๋“œ๋ž˜๊ณค ์ปค www.acmicpc.net ํ’€์ด #๋ฐฑ์ค€ 15685๋ฒˆ ๋ฌธ์ œ - ๋“œ๋ž˜๊ณค ์ปค๋ธŒ import sys input = sys.stdin.readline n = int(input()) dx = [1,0,-1,0] dy = [0,-1,0,1] # ์ขŒํ‘œ๊ฐ€ ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์— ํฌํ•จ์ด ๋˜๋Š”์ง€ ์ฒดํฌํ•ด์ค„ ๋ฆฌ์ŠคํŠธ check = [[0] * (101) for _ in range(101)] for _ in range(n): ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 14719๋ฒˆ_๋น—๋ฌผ

๋ฌธ์ œ https://www.acmicpc.net/status?user_id=wnstjd9701&problem_id=14719&from_mine=1 ์ฑ„์  ํ˜„ํ™ฉ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 14719๋ฒˆ ๋ฌธ์ œ - ๋น—๋ฌผ h, w = map(int, input().split()) world = list(map(int, input().split())) answer = 0 for i in range(1, w-1): left_max = max(world[:i]) right_max = max(world[i+1:]) compare = min(left_max, right_max) if world[i] < compare: answer += compare - world[i] print(answer) ๊ฐ€์žฅ ์ฒ˜์Œ๊ณผ ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold3] 14890๋ฒˆ_๊ฒฝ์‚ฌ๋กœ

๋ฌธ์ œ https://www.acmicpc.net/problem/14890 14890๋ฒˆ: ๊ฒฝ์‚ฌ๋กœ ์ฒซ์งธ ์ค„์— N (2 ≤ N ≤ 100)๊ณผ L (1 ≤ L ≤ N)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์ง€๋„๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์นธ์˜ ๋†’์ด๋Š” 10๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 14890๋ฒˆ ๋ฌธ์ œ - ๊ฒฝ์‚ฌ๋กœ n, l = map(int, input().split()) graph = [list(map(int, input().split())) for _ in range(n)] ans = 0 def check_line(line): for i in range(1, n): if abs(line[i] - line[i - 1]) > 1: return False if line[i] < lin..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver2] 2477๋ฒˆ_์ฐธ์™ธ๋ฐญ

๋ฌธ์ œ https://www.acmicpc.net/problem/2477 2477๋ฒˆ: ์ฐธ์™ธ๋ฐญ ์ฒซ ๋ฒˆ์งธ ์ค„์— 1m2์˜ ๋„“์ด์— ์ž๋ผ๋Š” ์ฐธ์™ธ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์–‘์˜ ์ •์ˆ˜ K (1 ≤ K ≤ 20)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฐธ์™ธ๋ฐญ์„ ๋‚˜ํƒ€๋‚ด๋Š” ์œก๊ฐํ˜•์˜ ์ž„์˜์˜ ํ•œ ๊ผญ์ง“์ ์—์„œ ์ถœ๋ฐœํ•˜์—ฌ ๋ฐ˜์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ ๋‘˜๋ ˆ๋ฅผ ๋Œ๋ฉด์„œ ์ง€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2477๋ฒˆ ๋ฌธ์ œ - ์ฐธ์™ธ๋ฐญ melon = int(input()) # ์ฐธ์™ธ ๊ฐœ์ˆ˜ K values = [input().split() for _ in range(6)] # ๋‚˜๋จธ์ง€ 2~7 line์˜ 6 ์ค„์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. directions = [int(v[0]) for v in values] # ๋ฐฉํ–ฅ์„ ๋ฝ‘์•„๋‚ด์„œ ์ €์žฅํ•œ๋‹ค. lengths = [int(v[1]) for v in val..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver2] 3085๋ฒˆ_์‚ฌํƒ• ๊ฒŒ์ž„

๋ฌธ์ œ https://www.acmicpc.net/problem/3085 3085๋ฒˆ: ์‚ฌํƒ• ๊ฒŒ์ž„ ์˜ˆ์ œ 3์˜ ๊ฒฝ์šฐ 4๋ฒˆ ํ–‰์˜ Y์™€ C๋ฅผ ๋ฐ”๊พธ๋ฉด ์‚ฌํƒ• ๋„ค ๊ฐœ๋ฅผ ๋จน์„ ์ˆ˜ ์žˆ๋‹ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 3085๋ฒˆ ๋ฌธ์ œ - ์‚ฌํƒ• ๊ฒŒ์ž„ n = int(input()) candy =[list(input()) for _ in range(n)] dx = [0,0,1,-1] dy = [1,-1,0,0] result = 0 temp = '' for i in range(n): for j in range(n): for k in range(4): nx = dx[k] + j ny = dy[k] + i if nx>=0 and ny>=0 and nx