[Coding Test]
![[백준] 1181: 단어 정렬](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FtwZLz%2FbtrGiu8HswM%2Fm0pVEpBOHxB91EAcKa4YH0%2Fimg.png)
[백준] 1181: 단어 정렬
1181번: 단어 정렬 import sysdef solution(): n = int(sys.stdin.readline().strip()) arr, answer = set(), [] for _ in range(n): arr.add(sys.stdin.readline().strip()) for i in arr: answer.append(i) answer.sort(key=lambda x: (len(x), x) ) for i in answer: print(i)solution()key=lambda x: (len(x), x) 이렇게 하면 "길이순 -> 사전 순" 정렬이 가능합니다.
![[백준] 1157: 단어 공부](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FAa4dT%2FbtrGgofDORl%2FOhBEMbOTNBTsqCKk6yCTL0%2Fimg.png)
[백준] 1157: 단어 공부
https://www.acmicpc.net/problem/1157 1157번: 단어 공부알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.www.acmicpc.net import sysfrom collections import Counterdef solution(): word = sys.stdin.readline().strip().upper() counter = Counter(word) max_count = max(counter.values()) most_common = [ char for char, count in counter.items() if count == max_..
![[백준] 1697: 숨바꼭질](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FS1MFr%2FbtrIJWocSed%2FK8zmDk6y77FiekYiLwqgY0%2Fimg.png)
[백준] 1697: 숨바꼭질
https://www.acmicpc.net/problem/1697수빈이가 5-10-9-18-17 순으로 가면 4초만에 동생을 찾을 수 있습니다.import sysfrom collections import dequedef solution(): n, k = map(int, sys.stdin.readline().split()) def bfs(): visited = [0]*100001 q = deque() q.append(n) while q: now = q.popleft() if now == k: return visited[now] for next in (now-1,..
![[백준] 7569: 토마토](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FGRAbt%2FbtrILd325wc%2FVwHRIXyBtD8R496qYO11F1%2Fimg.png)
[백준] 7569: 토마토
https://www.acmicpc.net/problem/7569 from collections import dequeimport sysdef solution(): m, n, h = map(int, sys.stdin.readline().split()) dx = [ 0, 0, -1, 1, 0, 0 ] # 세로 # 6방향 이동 (좌우, 상하, 위아래) dy = [ -1, 1, 0, 0, 0, 0 ] # 가로 dz = [ 0, 0, 0, 0, -1, 1 ] # 층 q = deque() tomato = [] for z in range(h): layer = [] for x in range(n): row = list(map(int, ..
![[백준] 2667: 단지번호붙이기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FYc8zr%2FbtrF4wkw4RB%2FITPpgycy2kYGJYwP5nsBwK%2Fimg.png)
[백준] 2667: 단지번호붙이기
https://www.acmicpc.net/problem/2667 from collections import dequen = int(input())graph = [ list(map(int, input())) for _ in range(n) ]dx = [ -1, 1, 0, 0 ]dy = [ 0, 0, -1, 1 ]answer = []cnt = 0 #1res = 0 #2def bfs(x, y): global cnt graph[x][y] = 2 #3 q = deque() q.append((x,y)) #4 while q: x, y = q.popleft() cnt += 1 #5 for i in range(4): nx = ..
![[백준] 1182: 부분수열의 합](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FLMrs4%2FbtrFVul7cQ4%2FTHh5HOP6J4ff0F2ir3a9E1%2Fimg.png)
[백준] 1182: 부분수열의 합
1182번: 부분수열의 합 import sysfrom itertools import combinationsn, s = map(int, sys.stdin.readline().split())arr = list(map(int, sys.stdin.readline().split()))def solution(n, s, arr): count = 0 for i in range(1, n+1): for num in combinations(arr, i): if sum(num) == s: count += 1 return countprint(solution(n, s, arr))부분 수열의 합이 s가 되는 경우를 구해야 하는 완전탐색 문제입니다.부분수열이..