문자열 7

[백준][Python] 25757 임스와 함께하는 미니게임

🃏 https://www.acmicpc.net/problem/25757 25757번: 임스와 함께하는 미니게임 첫 번째 줄에는 사람들이 임스와 같이 플레이하기를 신청한 횟수 $N$과 같이 플레이할 게임의 종류가 주어진다. $(1 \le N \le 100\,000)$ 두 번째 줄부터 $N$개의 줄에는 같이 플레이하고자 하는 사람들 www.acmicpc.net 내 풀이 (1차) N, game = input().split() names = [] player = 0 if game == 'Y': player = 1 elif game == 'F': player = 2 else: player = 3 for _ in range(int(N)): names.append(input()) print(len(set(names)..

코딩테스트 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] 9935 문자열 폭발

💣 https://www.acmicpc.net/problem/9935 9935번: 문자열 폭발 첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모 www.acmicpc.net 정답 코드 string = input() explosion = input() ans = [] last_char = explosion[-1] for i in string: ans.append(i) if i == last_char and ''.join(ans[-len(explosion):]) == explosion: del ans[-len(explosion):] if len(ans)..

코딩테스트 2024.03.24

[백준][Python] 1251 단어 나누기

🔤 https://www.acmicpc.net/problem/1251 1251번: 단어 나누기 알파벳 소문자로 이루어진 단어를 가지고 아래와 같은 과정을 해 보려고 한다. 먼저 단어에서 임의의 두 부분을 골라서 단어를 쪼갠다. 즉, 주어진 단어를 세 개의 더 작은 단어로 나누는 것이다 www.acmicpc.net 내 풀이 from itertools import combinations word = input() split_length = [x for x in range(len(word)-1)] split_index = [] split_words = [] for i in combinations(split_length, 2): split_index.append(list(i)) for i in range(len..

코딩테스트 2024.03.11

[백준][Python] 1141 접두사

🐉 https://www.acmicpc.net/problem/1141 1141번: 접두사 접두사X 집합이란 집합의 어떤 한 단어가, 다른 단어의 접두어가 되지 않는 집합이다. 예를 들어, {hello}, {hello, goodbye, giant, hi}, 비어있는 집합은 모두 접두사X 집합이다. 하지만, {hello, hell}, {giant, www.acmicpc.net 내 풀이 N = int(input()) words = [] ans = 0 for _ in range(N): words.append(input()) for i in range(N): for j in range(N): if i == j: continue if words[j].find(words[i]) == 0: # 0일 때 접두사 word..

코딩테스트 2024.03.02