(Python) 백준 1541 / 잃어버린 괄호
·
Coding Test Practice/Python
import sysfrom collections import dequeinput = sys.stdin.readline# 줄바꿈 문자 제거total = str(input()).rstrip()total_str = ""temp = ""# 00009-00009와 같은 상황에서 0을 제거해주는 부분for i in total: # -나 +를 만나면 누적 숫자를 int처리 + 부호를 더해줌 if i == "-" or i == "+": temp += str(int(total_str)) + i total_str = "" # 숫자를 계속 누적시키다가 else: total_str += i# 마지막 숫자는 더해지지 않으므로 여기서 더해줌total = temp + str(i..
(Python) 백준 5430 / AC
·
Coding Test Practice/Python
import sysfrom collections import dequeinput = sys.stdin.readlinetotal = int(input())# D는 1, R은 2로 해서 페어를 만들어 리스트를 구현 [D 또는 R, D 또는 R의 개수]# ex) DDRRRDDDR이면# [[1, 2], [2, 3], [1, 3], [2, 1]]def compress_string(s): if not s: return [] s = s.strip() # 문자열의 앞뒤 공백 문자를 제거 compressed = [] current_char = s[0] count = 1 for char in s[1:]: if char == current_char: ..
(Python) 백준 1003 / 피보나치 함수
·
Coding Test Practice/Python
로직값을 저장해서 빠른 속도로 결과를 냄 + return 0의 개수를 구해야 함 두가지 결과값을 모두 가져와야 하는 문제였다. 피보나치 40의 값이 어차피 100000000000을 넘지는 못하므로 0의 개수를 100000000000를 더하는 것으로 해결했다import sysinput = sys.stdin.readlineaa = int(input())def fibo(num, memo): if (memo[num - 1] > 0): return memo[num - 1] if num == 0: return 100000000000 elif num == 1: return 1 memo[num - 1] = fibo(num - 1, memo) + fibo(num - 2, memo) return ..
(Python) 백준 18110 / solved.ac
·
Coding Test Practice/Python
import sysinput = sys.stdin.readlinedef roundd(num): """ 자체 반올림 함수 """ if ((num % 1)
(Python) 백준 15829 / Hashing
·
Coding Test Practice/Python
1234567891로 나눈 나머지를 구하지 않아서 계속 50점이 나왔었다...import sysinput = sys.stdin.readlineasd = int(input())senten = str(input())[:asd]num = 0count = 0for i in senten: num += ((ord(i) - 96) * (31 ** count)) count += 1print(num % 1234567891)
(Python) 백준 2108 / 통계학
·
Coding Test Practice/Python
import sysfrom collections import Counter input = sys.stdin.readlineasd = int(input())llst = []for _ in range(asd): llst.append(int(input())) llst = sorted(llst)# 산술평균if (((sum(llst) / len(llst)) % 1) 1): print(l[1])else: print(l[0])# 범위print(max(llst) - min(llst))
(Python) 백준 7568 / 덩치
·
Coding Test Practice/Python
import sysfrom collections import dequeinput = sys.stdin.readlineasd = int(input())tl = [[] for _ in range(asd)]for i in range(asd): a, b = map(int, input().split()) tl[i].append(a) tl[i].append(b)for n in tl: count = 0 for k in tl: if ((k[0] > n[0]) and (k[1] > n[1])): count += 1 print(count + 1, end = " ")
(Python) 백준 2775 / 부녀회장이 될테야
·
Coding Test Practice/Python
풀이최대 입력개수가 1 ~ 14여서 간단하게 풀수있었다# # 1, 6, 21, 56# 1, 5, 15, 35, 70, 126# 1, 4, 10, 20, 35, 56# 1, 3, 6, 10, 15, 21# 1, 2, 3, 4, 5, 6import systemp = [[] for _ in range(15)]temp[0] = [i for i in range(15)]for i in range(1, 15): for n in range( 15): temp[i].append(0)for i in range(1, 15): for n in range(1, 15): temp[i][n] = sum(temp[i - 1][1:n + 1]) ..