1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline())
sequence = list(map(int,sys.stdin.readline().strip().split()))
result = [-1] * n
notFound = []
for i in range(n):
while len(notFound) > 0 and sequence.count(sequence[notFound[-1]]) < sequence.count(sequence[i]):
result[notFound.pop()] = sequence[i]
notFound.append(i)
print(' '.join(map(str,result)))
import sys
n = int(sys.stdin.readline())
sequence = list(map(int,sys.stdin.readline().strip().split()))
result = [-1] * n # 결과 출력할 리스트
count = [ 0 for i in range(1000001)] # 요소의 값을 인덱스로 하는 곳에 요소의 개수를 저장 (계수정렬원리)
notFound = []
for i in range(n):
count[sequence[i]] += 1
for i in range(n):
while len(notFound) > 0 and count[sequence[notFound[-1]]] < count[sequence[i]]:
result[notFound.pop()] = sequence[i]
notFound.append(i)
print(' '.join(map(str,result)))
3. Learned
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline())
pos_exp = sys.stdin.readline().strip()
operand = []
stack = []
for _ in range(n):
operand.append(int(sys.stdin.readline()))
for i in pos_exp:
if ord('A') <= ord(i) <= ord('Z'):
stack.append(operand[ord(i)-65]) # 피연산자면 push
else:
operand2 = stack.pop()
operand1 = stack.pop()
try:
stack.append(eval("operand1" + i + "operand2 ")) # 연산자면 두개를 pop 해서 연산 후 다시 push
except:
stack.append(0)
print(f"{stack[0]:.2f}")
3. Learned
1. Problem
A*(B+C) -> ABC+*
A+B*C+D*E+G -> ABC*+DE*+G+
A*B+C+D+E*F*G+E -> AB*C+D+EF*G*+E+
A+B*C*((D-E)*G) -> ABC*DE-G**+
2. Others' Solutions
import sys
exp = sys.stdin.readline().strip()
pos_exp = []
stack = []
for i in exp:
if i == '(':
stack.append(i)
elif i == '*' or i == '/':
while stack and (stack[-1]=='*' or stack[-1]=='/'):
pos_exp.append(stack.pop())
stack.append(i)
elif i == '+' or i == '-':
while stack and stack[-1] == stack[-1]!= '(':
pos_exp.append(stack.pop())
stack.append(i)
elif i == ')':
while stack[-1] != '(':
pos_exp.append(stack.pop())
stack.pop()
else:
pos_exp.append(i)
for i in range(len(stack)):
pos_exp.append(stack.pop())
print(''.join(map(str,pos_exp)))
3. Learned
while stack and stack[-1] == stack[-1]!= '(':