This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from collections import deque | |
if __name__ == '__main__': | |
n = int(input()) | |
L = deque() | |
for i in range(n): | |
cmdline = input().split() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
if __name__ == '__main__': | |
n, q = map(int, input().split()) | |
Q = deque() | |
for i in range(n): | |
name, time = input().split() | |
Q.append([name, int(time)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def push(x): | |
global stack | |
stack.append(x) | |
def pop(): | |
global stack | |
ret = stack.pop() | |
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ope = {"+": lambda a, b: b + a, | |
"-": lambda a, b: b - a, | |
"*": lambda a, b: b * a} | |
stack = [] | |
for c in input().split(): | |
if c in ope: | |
stack.append(ope[c](stack.pop(), stack.pop())) | |
else: | |
stack.append(int(c)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertionSort(A, n, g): | |
global cnt | |
for i in range(g, n): | |
v = A[i] | |
j = i - g | |
while j >= 0 and A[j] > v: | |
A[j + g] = A[j] | |
j = j - g | |
cnt = cnt + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selectionSort(A, N): | |
for i in range(N): | |
minj = i | |
for j in range(i, N): | |
if A[j][1:] < A[minj][1:]: | |
minj = j | |
if i != minj: | |
tmp = A[i] | |
A[i] = A[minj] | |
A[minj] = tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selectionSort(A, N): | |
global cnt | |
for i in range(N): | |
minj = i | |
for j in range(i, N): | |
if A[j] < A[minj]: | |
minj = j | |
if i != minj: | |
tmp = A[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bubbleSort(R, N): | |
flag = True | |
cnt = 0 | |
while flag == True: | |
flag = False | |
for j in range(N - 1, 0, -1): | |
if R[j] < R[j - 1]: | |
tmp = R[j] | |
R[j] = R[j - 1] | |
R[j - 1] = tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
n = int(input()) | |
R = [int(input()) for i in range(n)] | |
minv = R[0] | |
maxv = R[1] - R[0] | |
for j in range(1, n): | |
if (maxv < R[j] - minv): | |
maxv = R[j] - minv | |
if (R[j] < minv): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def sieve(x): | |
prime = [True for i in range(x)] | |
for i in range(2, int(math.sqrt(x))): | |
if prime[i] == True: | |
j = 0 | |
while i * (j + 2) < x: | |
prime[i * (j + 2)] = False |