1 | 10828 | ์คํ | ์ฑ๊ณต | 41369 | 108817 | 38.494% |
์คํ์ ๊ฐ๋ ์ ์ตํ๊ณ ์ค์ตํ๋ ๋ฌธ์ |
def push(num):
arrayList.append(num)
def pop() :
if len(arrayList) == 0 :
print(-1)
else :
print(arrayList.pop())
def size() :
print(len(arrayList))
def empty() :
if len(arrayList) == 0 :
print(1)
else :
print(0)
def top() :
if len(arrayList) == 0 :
print(-1)
else :
print(arrayList[-1])
import sys
arrayList = []
T = int(input())
for i in range(T) :
# a, b = list(map(str, input().split()))
N = sys.stdin.readline().rstrip().split()
a = N[0]
if a == "push" :
push(N[1])
elif a == "pop" :
pop()
elif a == "size" :
size()
elif a == "empty" :
empty()
elif a == "top" :
top()
2 | 10773 | ์ ๋ก | ์ฑ๊ณต์ถ์ฒ๋ค๊ตญ์ด | 17259 | 25888 | 67.809% |
๊ฐ์ฅ ์ต๊ทผ์ ์ด ์๋ฅผ ์ง์ฐ๋ ๋ฌธ์ |
arrayList = []
def puts(num) :
arrayList.append(num)
def pops() :
arrayList.pop()
T = int(input())
for i in range(T):
number = int(input())
if number != 0 :
puts(number)
else :
pops()
if i == T-1:
print(sum(arrayList))
3 | 9012 | ๊ดํธ | ์ฑ๊ณต์ถ์ฒ๋ค๊ตญ์ด | 38311 | 87721 | 42.490% |
์ฃผ์ด์ง ๋ฌธ์์ด์ด ์ฌ๋ฐ๋ฅธ ๊ดํธ์ด์ธ์ง ํ๋จํ๋ ๋ฌธ์ |
t = int(input())
for i in range(t) :
case = input()
b = list(case)
sum = 0
for j in b :
if j == '(' :
sum += 1
elif j == ')' :
sum -= 1
if sum < 0:
print('NO')
break
if sum > 0:
print('NO')
elif sum == 0:
print('YES')
4 | 4949 | ๊ท ํ์กํ ์ธ์ | ์ฑ๊ณต์ถ์ฒ๋ค๊ตญ์ด | 11168 | 33926 | 32.720% |
์์ ๊ฐ์๋ฐ ๊ดํธ์ ์ข ๋ฅ๊ฐ ๋ค์ํด์ง ๋ฌธ์ |
while True :
x = input()
if x == '.' :
break
list = []
tf = True
for i in x :
if i == '[' or i == '(' :
list.append(i)
elif i == ']' :
if len(list) == 0 or list[-1] != '[':
tf = False
break
list.pop(-1)
elif i == ')' :
if len(list) == 0 or list[-1] != '(':
tf = False
break
list.pop(-1)
if tf and len(list) ==0:
print("yes")
else :
print("no")
5 | 1874 | ์คํ ์์ด | ์ฑ๊ณต | 20456 | 59058 | 34.340% |
์คํ์ ํ์ฉํ๋ ๋ฌธ์ |
s = []
outputList = []
temp = True
count = 1
for i in range(int(input())):
num = int(input())
while count <= num:
s.append(count)
outputList.append('+')
count += 1
if s[-1] == num:
s.pop()
outputList.append('-')
else:
temp = False
if temp == False:
print('NO')
else:
for i in outputList:
print(i)
6 | 17298 | ์คํฐ์ | ์ฑ๊ณต | 6139 | 17993 | 34.183% |
์คํ์ผ๋ก ํ ์ ์๋ ๊ฝค ์ด๋ ค์ด ๋ฌธ์ |
import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
stack = []
answer = [-1 for i in range(n)]
for i in range(len(arr)):
while stack and arr[stack[-1]] < arr[i]:
answer[stack.pop()] = arr[i]
stack.append(i)
print(*answer)
#์ฒ์์ ์๋์ฒ๋ผํด์ ์๊ฐ์ด๊ณผ๋จ
# import sys
# t = int(sys.stdin.readline())
# list = list(map(int, sys.stdin.readline().split()))
# for i in range(t) :
# list02 = list[:]
# point = list02[i]
# temp = -1
# while True :
# popNum = list02.pop()
# if popNum > point :
# temp = popNum
# elif point == popNum :
# break
# print(temp, end=" ")
728x90
๋ฐ์ํ