백준5 [Python] 백준 14720번 우유 축제 n = int(input()) store = list(map(int,input().split())) cnt = 0 for i in range(n): if store[i] == cnt % 3: cnt += 1 print(cnt) 같이 문제를 풀었던 친구는 아래와 같은 식으로 풀었다. input() store = list(input().split()) cnt = 0 milk_state = 0 for i in store: if int(i) == milk_state: milk_state += 1 cnt += 1 if milk_state > 2: milk_state = 0 print(cnt) 개발/Algorithm 2021. 11. 15. [Python] 백준 15649번 N과 M (1) itertools를 이용해 간단히 풀어보자 from itertools import permutations N, M = map(int, input().split()) P = permutations(range(1, N + 1), M) # iter(tuple) for i in P: print(" ".join(map(str, i))) # tuple -> str 개발/Algorithm 2021. 11. 15. [Python] 백준 1260번 DFS와 BFS from collections import deque def DFS(graph, root): visited = [] stack = [root] while stack: n = stack.pop() if n not in visited: visited.append(n) if n in graph: temp = list(set(graph[n]) - set(visited)) temp.sort(reverse=True) stack += temp return " ".join(str(i) for i in visited) def BFS(graph, root): visited = [] queue = deque([root]) while queue: n = queue.popleft() if n not in visited: vis.. 개발/Algorithm 2021. 11. 12. [Python] 백준 10814번 나이순 정렬 n = int(input()) a = [] for _ in range(n): age,name = map(str,input().split()) age = int(age) a.append((age, name)) a.sort(key=lambda x: x[0]) for i in range(n): #리스트 안의 리스트 깔끔하게 출력하기 print(*a[i],sep=' ') 처음에 그냥 바로 a.append(input().split())으로 받아서 정렬했는데, 그럼 한자리수와 비교가 제대로 안되는 문제가 있어서 정확히 int로 명시해주고 나서 append를 진행했더니 해결되었다. 개발/Algorithm 2021. 11. 11. [Python] 백준 1181번 단어 정렬 import sys n = int(sys.stdin.readline()) a = [] for i in range(n): m = input() if m not in a: a.append(m) c = sorted(a) b = sorted(c, key = len) for i in b: print(i) 개발/Algorithm 2021. 11. 10. 이전 1 다음