구현 14

[백준][Python] 7568 덩치

💪🏻https://www.acmicpc.net/problem/7568  내 풀이N = int(input())weight = []height = []rank = []for _ in range(N): w, h = map(int, input().split()) weight.append(w) height.append(h)for i in range(N): cw = weight[i] ch = height[i] big = 0 for j in range(N): if cw  ✔️ 나보다 덩치가 큰 사람 ➡ 나보다 몸무게가 많이 나가면서 나보다 키가 큰 사람  코드 설명 weight: 몸무게를 저장하는 리스트height: 키를 저장하는 리스트rank: 덩치 등수를 저장..

코딩테스트 2024.05.12

[백준][Python] 2960 에라토스테네스의 체

♾️ https://www.acmicpc.net/problem/2960 2960번: 에라토스테네스의 체 2, 4, 6, 8, 10, 3, 9, 5, 7 순서대로 지워진다. 7번째 지워진 수는 9이다. www.acmicpc.net 내 풀이 N, K = map(int, input().split()) num = list(i for i in range(2, N+1)) ans = [] current_num = num[0] prime = num[0] # prime의 배수를 지워야 함 while num: while current_num 0: current_num = num[0] prime = num[0] print(ans[K-1]) 코드 설명 num: 2부터 N까지의 모든 정수를 저장하는 리스트 ans: 정답 리스트..

코딩테스트 2024.04.13

[백준][Python] 11723 집합

🌅 https://www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net 내 풀이 import sys M = int(sys.stdin.readline()) S = set() for _ in range(M): command = sys.stdin.readline().split() c1 = command[0] if len(command) == 2: c2 = int(command[1]) # add if c1 == 'add': S.add(c2) # remove elif c1 == 'remove': S.disc..

코딩테스트 2024.04.01

[백준][Python] 10431 줄세우기

👩🏻‍🎓 https://www.acmicpc.net/problem/10431 10431번: 줄세우기 초등학교 선생님 강산이는 아이들을 데리고 단체로 어떤 일을 할 때 불편함이 없도록 새로 반에 배정받은 아이들에게 키 순서대로 번호를 부여한다. 번호를 부여할 땐 키가 가장 작은 아이가 1 www.acmicpc.net 내 풀이 P = int(input()) for _ in range(P): lst = list(map(int, input().split())) T = lst[0] height = lst[1:] line_up = [height[0]] # 첫 번째 학생 추가 ans = 0 for i in range(1, 20): if height[i] > max(line_up): # 자기 앞에 자기보다 키가 큰 학..

코딩테스트 2024.03.31

[백준][Python] 22251 빌런 호석

🛗 https://www.acmicpc.net/problem/22251 22251번: 빌런 호석 LED를 2개까지 바꿀 수 있을 때, 5층에서 3층, 6층, 8층, 그리고 9층으로 바꿔버릴 수 있다. www.acmicpc.net 내 풀이 def onoff(nX): global result ans = 0 if nX N: return currentX = list(f'{X:0{K}d}') currentnX = list(f'{nX:0{K}d}') for i in range(K): currentXNum = num[currentX[i]].copy() currentnXNum = num[currentnX[i]].copy() common_values = [value for value in curre..

코딩테스트 2024.03.30

[백준][Python] 9017 크로스 컨트리

🏃🏻‍♀️ https://www.acmicpc.net/problem/9017 9017번: 크로스 컨트리 입력 데이터는 표준입력을 사용한다. 입력은 T 개의 테스트 케이스로 주어진다. 입력 파일의 첫 번째 줄에 테스트 케이스의 수를 나타내는 정수 T 가 주어진다. 두 번째 줄부터는 두 줄에 하나의 www.acmicpc.net 정답 코드 T = int(input()) for _ in range(T): N = int(input()) t = list(map(int, input().split())) out = [] # 참가 선수가 6명 미만인 팀 번호 저장 score = {} # 6명 미만인 팀 번호 저장 for i in t: if t.count(i) < 6: out.append(i) else: # 점수 초기화 ..

코딩테스트 2024.03.29

[백준][Python] 7490 0 만들기

🧮 https://www.acmicpc.net/problem/7490 7490번: 0 만들기 각 테스트 케이스에 대해 ASCII 순서에 따라 결과가 0이 되는 모든 수식을 출력한다. 각 테스트 케이스의 결과는 한 줄을 띄워 구분한다. www.acmicpc.net 내 풀이 def dfs(n, s): if n == N: s += str(N) ns = ''.join(s.split()) if eval(ns) == 0: ans.append(s) return dfs(n+1, s + str(n) + '+') dfs(n+1, s + str(n) + '-') dfs(n+1, s + str(n) + ' ') T = int(input()) for _ in range(T): ans = [] N = int(input()) df..

코딩테스트 2024.03.28

[백준][Python] 10828 스택

📚 https://www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 내 풀이 import sys N = int(sys.stdin.readline()) stack = [] for _ in range(N): command = list(sys.stdin.readline().split()) if command[0] == 'push': stack.append(command[1]) elif command[0] == 'pop': if len(stack) ..

코딩테스트 2024.03.27