코테 대비 python/백준
-
1158 요세푸스코테 대비 python/백준 2023. 2. 6. 19:36
https://www.acmicpc.net/problem/1158 1158번: 요세푸스 문제 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000) www.acmicpc.net ####시간 84ms ####메모리 34244KB #rotate?? #import sys #input = sys.stdin.readline from collections import deque n, k = map(int,input().split()) a= [_+1 for _ in range(n)] queue = deque(a) result = [] while queue: #왼쪽으로 돌려야해 queue.rotate(-k+1) b= queue.popleft() result.append(b) ..
-
2231 분해합코테 대비 python/백준 2023. 2. 3. 17:14
https://www.acmicpc.net/problem/2231 2231번: 분해합 어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이 www.acmicpc.net n = int(input()) result = 0 for i in range(1,n+1): s= list(map(int,str(i))) result = i +sum(s) if result == n: print(i) break if i==n: print(0)
-
1874 스택==> 다시풀기코테 대비 python/백준 2023. 2. 3. 15:02
https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net count = 1 temp = True stack = [] op = [] N = int(input()) for i in range(N): num = int(input()) while count
-
2800 스택 ==> 다시풀어보기코테 대비 python/백준 2023. 2. 2. 23:41
https://www.acmicpc.net/problem/2800 2800번: 괄호 제거 첫째 줄에 음이 아닌 정수로 이루어진 수식이 주어진다. 이 수식은 괄호가 올바르게 쳐져있다. 숫자, '+', '*', '-', '/', '(', ')'로만 이루어져 있다. 수식의 길이는 최대 200이고, 괄호 쌍은 적어도 1개 www.acmicpc.net #쌍이 되는 괄호를 제거 한다 #사전 순으로 출력한다? 어떤 의미?? import sys def input(): return sys.stdin.readline().rstrip() s = input() N = len(s) index = [ -1 for _ in range(N) ] stack = [] current_index = 0 # 올바른 괄호만 주어진다. 각 괄호..
-
2346 덱 rotate코테 대비 python/백준 2023. 2. 2. 16:42
https://www.acmicpc.net/problem/2346 2346번: 풍선 터뜨리기 1번부터 N번까지 N개의 풍선이 원형으로 놓여 있고. i번 풍선의 오른쪽에는 i+1번 풍선이 있고, 왼쪽에는 i-1번 풍선이 있다. 단, 1번 풍선의 왼쪽에 N번 풍선이 있고, N번 풍선의 오른쪽에 1번 풍선 www.acmicpc.net from collections import deque n=int(input()) #딕셔너리에 키와 벨류 값을 넣어야 겠다. value = list(map(int, input().split())) ballon = dict() for _ in range(n): ballon[_+1] = value[_] #덱에 풍선들을 넣어야 겠다 왜??? => 값에 따라서 왼쪽 오른쪽 #pop()오른..
-
15651 N과 M코테 대비 python/백준 2023. 1. 31. 15:21
https://www.acmicpc.net/problem/15651 15651번: N과 M (3) 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해 www.acmicpc.net #중복이 포함되어 있으므로, combination이나 permutation적용 불가 N,M = map(int,input().split()) choice = [0 for _ in range(M)] def recursion(i): if i ==M: for j in choice: print(str(j),end=' ') print() else: for k in range(1,N+1): choice[i]..
-
5622 문자열코테 대비 python/백준 2023. 1. 31. 11:42
https://www.acmicpc.net/problem/5622 5622번: 다이얼 첫째 줄에 알파벳 대문자로 이루어진 단어가 주어진다. 단어의 길이는 2보다 크거나 같고, 15보다 작거나 같다. www.acmicpc.net s=input() total=0 for i in s: if i in "ABC": total+=3 elif i in "DEF": total+=4 elif i in "GHI": total+=5 elif i in "JKL": total+=6 elif i in "MNO": total+=7 elif i in "PQRS": total+=8 elif i in "TUV": total+=9 elif i in "WXYZ": total+=10 else: pass print(total) https://..