(Python) 백준 1966 / 프린터 큐
·
Coding Test Practice/Python
로직llst에 가중치와 번호가 매겨진다, ex) [[1, 0], [2, 1], [3, 2], [4, 3]]llst 전체를 순회하며 0번 가중치보다 큰 가중치가 존재하면? --> 0번 문서를 가장 뒤로 보낸다0번 문서의 가중치가 가장 클경우 출력한다방금 출력한 문서가 목표한 문서면 횟수를 출력하고 아닐시 반복한다.import sysfrom collections import dequeinput = sys.stdin.readlinea = int(input())for i in range(a): llst = deque() num = 0 temp = [] b, c = map(int, input().split()) tmp = list(map(int, input().split())) for k in rang..
(Python) 백준 1874 / 스택 수열
·
Coding Test Practice/Python
초기 코드stack 내부에 수열을 하나씩 push, pop 하면서 비교하는 방식은 시간초과를 벗어날 수 없었다.import sysfrom collections import dequeinput = sys.stdin.readlinea = int(input())b = deque() # 4, 3, 6, 8, 7, 5, 2, 1c = deque() # 1, 2, 3, 4, 5, 6, 7, 8d = deque() # emptyoper = deque() # + -for i in range(a): b.append(int(input())) c.append(i + 1) while True: if not b: for k in oper: print(k) break if not d: d.app..
(Python) 백준 1914 / 하노이의 탑
·
Coding Test Practice/Python
c++ 시각화시각화 코드는 c++로 짰지만 2**100을 담기가 어려워 답안 제출은 파이썬으로 했다#include #include #include #include #include enum path{ START = -1, TEMP = -2, END = -3};using namespace std;char LM[10] = "L -> M";char LR[10] = "L -> R";char ML[10] = "M -> L";char MR[10] = "M -> R";char RM[10] = "R -> M";char RL[10] = "R -> L";int ss, ee, tt;vector sss;vector eee;vector ttt;int N;int index;int total_num;ofstream ..
(Python) 백준 1929 / 소수 구하기
·
Coding Test Practice/Python
소수를 간단히 구하는 법n의 약수는 무조건 n의 제곱근 이하에만 존재한다고 한다.따라서 n이 소수인지 판별하려면 n**(1/2)까지만 반복문을 돌려보며 나누면 된다코드a, b = map(int, input().split())if a == 1: a = 2# a가 1이면 2로 바꿔줌tl = [i for i in range(a, b + 1) if i % 2 != 0]# 짝수 전부 제거if a == 2: tl.insert(0, 2)# 짝수를 제거하면서 삭제된 2 추가for j in tl: checkk = 0 # 0이 유지되면 소수, 아니면 합성수 kk = int(j ** (1/2)) + 1 # 제곱근을 구해주는 과정 for k in range(2, kk): # 제곱근 이하의 수로만 나눠봄 ..
(Python) 백준 10773 / 제로
·
Coding Test Practice/Python
queue 연습용import sysfrom collections import dequeinput = sys.stdin.readlinequeue = deque()iii = int(input())a = 0for _ in range(iii): aaa = int(input()) if aaa != 0: queue.append(aaa) else: queue.pop() for i in queue: a += iprint(a)
(Python) 백준 11651 / 좌표 정렬하기 2
·
Coding Test Practice/Python
import sysinput = sys.stdin.readlinetotal_num = int(input())total_list = [[] for _ in range(200001)]for _ in range(total_num): a, b = map(int, input().split()) b += 100000 total_list[b].append(a) for i in range(0, 200001): if total_list[i]: total_list[i] = sorted(total_list[i]) for j in total_list[i]: print(j, i - 100000)
(Python) 백준 11866 / 요세푸스 문제 0
·
Coding Test Practice/Python
import sysfrom collections import dequeinput = sys.stdin.readlinea, b = map(int, input().split())queue = deque()result = []for i in range(1,a + 1): queue.append(i)while queue: for _ in range(b - 1): queue.append(queue.popleft()) result.append(queue.popleft()) print("")
(Python) 백준 10816 / 숫자 카드 2
·
Coding Test Practice/Python
import sysfrom collections import Counter # Counter 모듈 사용input = sys.stdin.readlinetemp = []a = int(input())b = list(map(int, input().split()))c = int(input())d = list(map(int, input().split()))count = Counter(b)for i in range(len(d)): if d[i] in count: print(count[d[i]], end=' ') else: print(0, end=' ')