[Baekjoon] 1676 ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : https://www.acmicpc.net/problem/1676 1676๋ฒˆ: ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜ N!์—์„œ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฒ˜์Œ 0์ด ์•„๋‹Œ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ฌ ๋•Œ๊นŒ์ง€ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net โ–ถ ์ฝ”๋“œ : let input = require('fs').readFileSync(`Computer Science/Alogrithms/๋ฐฑ์ค€JS/testCase.txt`).toString().split('\n'); function count5(num){ let count = 0; while(num % 5 === 0){ num = parseInt(num / 5) count += 1; } return count } const inputNum = parseInt(input[0]..
[Baekjoon] 1389๋ฒˆ ์ผ€๋นˆ ๋ฒ ์ด์ปจ์˜ 6๋‹จ๊ณ„ ๋ฒ•์น™
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : https://www.acmicpc.net/problem/1389 1389๋ฒˆ: ์ผ€๋นˆ ๋ฒ ์ด์ปจ์˜ 6๋‹จ๊ณ„ ๋ฒ•์น™ ์ฒซ์งธ ์ค„์— ์œ ์ €์˜ ์ˆ˜ N (2 ≤ N ≤ 100)๊ณผ ์นœ๊ตฌ ๊ด€๊ณ„์˜ ์ˆ˜ M (1 ≤ M ≤ 5,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์—๋Š” ์นœ๊ตฌ ๊ด€๊ณ„๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์นœ๊ตฌ ๊ด€๊ณ„๋Š” A์™€ B๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, A์™€ B๊ฐ€ ์นœ๊ตฌ๋ผ๋Š” ๋œป www.acmicpc.net โ–ถ ์ฝ”๋“œ : let input = require('fs').readFileSync(`Computer Science/Alogrithms/๋ฐฑ์ค€JS/testCase.txt`).toString().split('\n'); const [n, m] = input[0].split(' ').map(num => parseInt(num)) let kevin..
[BaekJoon] 1620 ๋‚˜๋Š”์•ผ ํฌ์ผ“๋ชฌ ๋งˆ์Šคํ„ฐ ์ด๋‹ค์†œ
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://www.acmicpc.net/problem/1620 โ–ถ ์ฝ”๋“œ : n, m = map(int, input().split()) numToName = {} nameToNum = {} question = [] nums = ['0','1','2','3','4','5','6','7','8','9'] for i in range(1,n+1): data = input() numToName[i] = data nameToNum[data.lower()] = i for i in range(m): question.append(input().lower()) for q in question: if q[0] in nums: print(numToName[int(q)]) else: print(nameTo..
[BaekJoon] 1541 ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://www.acmicpc.net/problem/1541 โ–ถ ์ฝ”๋“œ : expr = input() tempExpr = '' tempNum = '' # + ๊ธฐํ˜ธ๋ฅผ ํฌํ•จํ•˜๋ฉด ๋ง์…ˆ์„ ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜ def exprSum(strData): if '+' in strData: for i in range(len(strData)): if strData[i] == '+': return str(int(strData[:i]) + int(strData[i+1:])) return strData # ์šฐ์„ ์ ์œผ๋กœ ์‹์— ํฌํ•จ๋œ + ๊ธฐํ˜ธ๋ฅผ ์ด์šฉํ•œ ๋ง์…ˆ์„ ์ง„ํ–‰ ์‹์—์„œ + ๊ธฐํ˜ธ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์€ ๋ชจ๋‘ ๋”ํ•ด์คŒ for i in range(len(expr)): if i == len(expr) - 1: tempNum += ex..
[BaekJoon] 1463 1๋กœ ๋งŒ๋“ค๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://www.acmicpc.net/problem/1463 โ–ถ ์ฝ”๋“œ : num = int(input()) data = {1:0} i = 2 while True: if i == num+1: break data[i] = data[i-1] + 1 if i % 3 == 0: data[i] = min(data[i], data[i//3] + 1) if i % 2 == 0: data[i] = min(data[i], data[i//2] + 1) i += 1 print(data[num]) โ–ถ ๋ฌธ์ œ ํ’€์ด : 1. DP ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ด์„œ ํ’€์ดํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. 2. ์ดˆ๊ธฐ ๊ฐ’ 1์„ ์ œ์™ธํ•œ ์ดํ›„ ์ˆซ์ž(2) ๋ถ€ํ„ฐ ๋ฐ˜๋ณต์„ ์ง„ํ–‰ํ•œ๋‹ค. 3. ํ•ด๋‹น ์ˆซ์ž์—์„œ 1์„ ๋บ€ ๊ฒฝ์šฐ(์ด ๊ฒฝ์šฐ๋Š” ์ด์ „ ๊ฒฐ๊ณผ๊ฐ’์— 1์„ ๋”ํ•จ) 3์œผ๋กœ..
[BaekJoon] 1107 ๋ฆฌ๋ชจ์ปจ
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ : ๋”๋ณด๊ธฐ https://www.acmicpc.net/problem/1107 โ–ถ ์ฝ”๋“œ : N = int(input()) M = int(input()) if M > 0 : errorBtn = list(map(int, input().split())) else: errorBtn =[] answer = abs(100 - N) for num in range(1000001): # ์ตœ๋Œ€ N์€ 500,000 ๊นŒ์ง€ ์ž…๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ ๊ฐ™์€ ์ž๋ฆฌ๋กœ ์ƒ๊ฐํ–ˆ์„๋•Œ 1,000,000 ๊นŒ์ง€ ์ž…๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ๋ฒ”์œ„๋ฅผ ์ด์™€ ๊ฐ™์ด ์„ค์ • # 1,000,000์„ ๋„˜์–ด๊ฐ€๋Š” ์ˆซ์ž๋ถ€ํ„ฐ๋Š” 0 ~ 500,000์‚ฌ์ด์˜ ์ˆซ์ž๋กœ ์ปค๋ฒ„ ๊ฐ€๋Šฅ count = 0 for c in str(num): if int(c) in errorBtn: break els..
[BaekJoon] 1074๋ฒˆ Z
ยท
๐Ÿ’ฏ CodingTest/BaekJoon
โ–ถ ๋ฌธ์ œ ๋”๋ณด๊ธฐ https://www.acmicpc.net/problem/1074 โ–ถ ์ฝ”๋“œ N, r, c = map(int, input().split()) l = 2 ** N def recursiveZ (x, y, l, startIndex): global answer, r, c if l == 2: if (x,y) == (r,c): answer = startIndex elif (x,y+1) == (r,c): answer = startIndex + 1 elif (x+1,y) == (r,c): answer = startIndex + 2 elif (x+1,y+1) == (r,c): answer = startIndex + 3 elif l > 2 : dividedL = l // 2 if r < dividedL an..