본문 바로가기

Python257

[백준 1759번] 암호 만들기 1759번: 암호 만들기 첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다. www.acmicpc.net import copy l, c = map(int,input().split()) alpha_set = set(input().split()) answer = [] vowels = set(['a','e','i','o','u']) # 암호는 서로 다른 L개의 알파벳 소문자들로 구성 # 최소 한 개의 모음(a, e, i, o, u)과 최소 두 개의 자음으로 구성 # 암호를 이루는 알파벳이 암호에서 증가하는 순서로 배열되었을 것 def dfs(string,remain_set):.. 2024. 1. 15.
[백준 2529번] 부등호 2529번: 부등호 두 종류의 부등호 기호 ‘’가 k개 나열된 순서열 A가 있다. 우리는 이 부등호 기호 앞뒤에 서로 다른 한 자릿수 숫자를 넣어서 모든 부등호 관계를 만족시키려고 한다. 예를 들어, 제시 www.acmicpc.net import copy k = int(input()) signs = list(input().split()) minimum, maximum = float("inf"), float("-inf") def dfs(numbers,num_set): global minimum, maximum, minimum_string, maximum_string length = len(numbers) if length == k+1: # 숫자의 개수가 k+1를 만족할 경우 함수 종료 final_value.. 2024. 1. 15.
[백준 1240번] 노드사이의 거리 1240번: 노드사이의 거리 첫째 줄에 노드의 개수 $N$과 거리를 알고 싶은 노드 쌍의 개수 $M$이 입력되고 다음 $N-1$개의 줄에 트리 상에 연결된 두 점과 거리를 입력받는다. 그 다음 줄에는 거리를 알고 싶은 $M$개의 노드 쌍 www.acmicpc.net from collections import deque n,m = map(int,input().split()) graph = [[] for _ in range(n+1)] for _ in range(n-1): # n-1개의 간선을 입력받고, 양방향으로 저장 start, end, distance = map(int,input().split()) graph[start].append((end,distance)) graph[end].append((star.. 2024. 1. 8.
[백준 14889번] 스타트와 링크(재풀이) 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net [백준 14889번] 스타트와 링크 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net n = int(input()) visited = [False for _ in range(n)] data = woohyun-king.tistory.com from itertools import combinations from ite.. 2024. 1. 6.
[백준 11123번] 양 한마리... 양 두마리... 11123번: 양 한마리... 양 두마리... 얼마전에 나는 불면증에 시달렸지... 천장이 뚫어져라 뜬 눈으로 밤을 지새우곤 했었지. 그러던 어느 날 내 친구 광민이에게 나의 불면증에 대해 말했더니 이렇게 말하더군. "양이라도 세봐!" www.acmicpc.net import sys from collections import deque input = sys.stdin.readline t = int(input().rstrip()) dx = [-1,1,0,0] dy = [0,0,-1,1] for _ in range(t): h,w = map(int,input().split()) answer = 0 area = [list(input().rstrip()) for _ in range(h)] visited = [[F.. 2024. 1. 6.
[백준 20291번] 파일 정리 20291번: 파일 정리 친구로부터 노트북을 중고로 산 스브러스는 노트북을 켜자마자 경악할 수밖에 없었다. 바탕화면에 온갖 파일들이 정리도 안 된 채 가득했기 때문이다. 그리고 화면의 구석에서 친구의 메시지를 www.acmicpc.net import sys from collections import Counter input = sys.stdin.readline n = int(input().rstrip()) texts = [input().rstrip().split(".")[1] for _ in range(n)] for name, count in sorted(list(dict(Counter(texts)).items()),key=lambda x: x[0]): print(f"{name} {count}") 이번 .. 2024. 1. 6.