1. Problem
2. My Solution
import sys
def L():
global cursor
if cursor == 0:
return
cursor -= 1
def D():
global cursor, string
if cursor == len(string):
return
cursor += 1
def B():
global cursor
if cursor == 0:
return
del string[cursor-1]
cursor -= 1
def P(word):
global cursor, string
if cursor == len(string):
string.append(word)
cursor += 1
else:
string.insert(cursor,word)
cursor += 1
string = list(sys.stdin.readline().strip())
n = int(sys.stdin.readline().strip())
cursor = len(string)
for _ in range(n):
instruction = sys.stdin.readline().strip().split()
if instruction[0] == 'L':
L()
elif instruction[0] == 'D':
D()
elif instruction[0] == 'B':
B()
else:
P(instruction[1])
print(''.join(string))
def P(word):
global cursor, string
if cursor == len(string):
string.append(word)
cursor += 1
else:
string = string[0:cursor] + list(word) + string[cursor:]
cursor += 1
3. Others' Solutions
import sys
def L():
global left_stack,right_stack
try:
right_stack.append(left_stack.pop())
except:
return
def D():
global left_stack,right_stack
try:
left_stack.append(right_stack.pop())
except:
return
def B():
global left_stack,right_stack
try:
left_stack.pop()
except:
return
def P(word):
global left_stack,right_stack
left_stack.append(word)
left_stack = list(sys.stdin.readline().strip())
right_stack = []
n = int(sys.stdin.readline().strip())
for _ in range(n):
instruction = sys.stdin.readline().strip().split()
if instruction[0] == 'L':
L()
elif instruction[0] == 'D':
D()
elif instruction[0] == 'B':
B()
else:
P(instruction[1])
print(''.join(map(str,left_stack)),end="")
print(''.join(map(str,right_stack))[::-1])
4. Learned
start = time.time()
...수행부분...
print(time.time() - start)
1. Problem
2. My Solution
import sys
def push(x):
global back_pointer
queue[back_pointer] = x
back_pointer += 1
def pop():
global front_pointer
if empty() == True:
print(-1)
else:
print(queue[front_pointer])
front_pointer += 1
def size():
print(back_pointer - front_pointer)
def front():
if empty() == True:
print(-1)
else:
print(queue[front_pointer])
def back():
if empty() == True:
print(-1)
else:
print(queue[back_pointer-1])
def empty():
if front_pointer == back_pointer:
return True
else:
return False
n = int(sys.stdin.readline().strip())
queue = [0 for _ in range(10001)]
front_pointer = 0
back_pointer = 0
for _ in range(n):
instruction = sys.stdin.readline().strip().split()
if instruction[0] == 'push':
push(instruction[1])
elif instruction[0] == 'pop':
pop()
elif instruction[0] == 'size':
size()
elif instruction[0] == 'front':
front()
elif instruction[0] == 'back':
back()
else:
if empty() == True:
print(1)
else:
print(0)
3. Others' Solutions
import sys
N = int(sys.stdin.readline())
queue = []
for i in range(N):
cmd = sys.stdin.readline().split()
if cmd[0] == "push":
queue.insert(0, cmd[1])
##print(queue)
elif cmd[0] == "pop":
if len(queue) != 0: print(queue.pop())
else: print(-1)
elif cmd[0] == "size":
print(len(queue))
elif cmd[0] == "empty":
if len(queue) == 0: print(1)
else : print(0)
elif cmd[0] == "front":
if len(queue) == 0: print(-1)
else: print(queue[len(queue) -1])
elif cmd[0] == "back":
if len(queue) == 0: print(-1)
else: print(queue[0])
4. Learned
1. Problem
2. My Solution
import sys
n,k = map(int,sys.stdin.readline().strip().split())
circle = [i for i in range(1,n+1)]
index = k-1
result = []
while(True):
result.append(circle[index % len(circle)])
del circle[index % len(circle)]
index += k-1
if len(circle) == 0:
break
index = index % len(circle)
print("<",end="")
print(', '.join(map(str,result)),end="")
print(">")
3. Others' Solutions
4. Learned