목록전체 글 (601)
sm 기술 블로그
from collections import deque from operator import indexOf import sys input = sys.stdin.readline N, M = map(int, input().split()) num = deque(i for i in range(1, N+1)) innum = deque(list(map(int, input().split()))) cnt = 0 while True: if num[0] == innum[0]: num.popleft() innum.popleft() if innum: continue else: break if len(num) // 2 >= num.index(innum[0]): while num[0] != innum[0]: num.append(n..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int N = Integer.parseInt(br.readLine()); Deque queue = new ArrayDeque(); for (int i = 0; i < N; i++) { String[] tmp = br.readLine().split(" "); String S; int num = 0; if(tmp..
from collections import deque import sys input = sys.stdin.readline N = int(input()) queue = deque([]) result = [] for _ in range(N): tmp = list(input().split()) S = '' num = 0 if len(tmp) == 1: S = tmp[0] else: S = tmp[0] num = int(tmp[1]) if S == 'push_back': queue.append(num) elif S == 'push_front': queue.appendleft(num) elif S == 'pop_front': if queue: result.append(str(queue.popleft())) els..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()); for(int i =0; i< T; i++) { String[] tmp = br.readLine().split(" "); int N = Integer.parseInt(tmp[0]); int M = Integer.parseInt(tmp[1..