1. Problem
2. My Solution
import sys
s = sys.stdin.readline().strip()
word =''
tag = False
for i in s:
if i == '<':
tag = True # 해당 부분부터 태그로 인식
print(word[::-1],end="") # 전에 단어가 존재했으면 역순으로 출력
word ='' # word 초기화
word += i
elif i == '>':
tag = False # 해당 부분부터 태그 해제
word += i
print(word,end="") # 태그 출력
word = '' # word 초기화
elif i == ' ' and tag == False: # 태그가 아닌 구간에서 ' ' 공백이면 단어의 끝을 의미
print(word[::-1]+" ",end ="") # 단어 역순으로 출력
word ='' # word 초기화
else:
word += i
print(word[::-1]) # 태그가 아닌 word 가 남았다면 역순으로 출력
3. Learned
1. Problem
2. Others' Solutions
import sys
p = sys.stdin.readline().strip()
stack = []
raser = False
count = 0
for i in p:
if i == '(':
stack.append(i)
raser = False
elif raser == False:
stack.pop()
count += len(stack)
raser = True
else:
stack.pop()
count += 1
print(count)
3. Learned
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline().strip())
sequence = list(reversed(list(map(int,sys.stdin.readline().strip().split()))))
result = []
while(len(sequence) > 1):
found = False
i = sequence.pop()
for j in range(len(sequence)-1,-1,-1):
if i < sequence[j]:
found = True
result.append(sequence[j])
break
if found == False:
result.append(-1)
print(' '.join(map(str,result)), -1)
3. Others' Solutions
import sys
test_n = int(sys.stdin.readline().strip())
sequence = list(map(int,sys.stdin.readline().strip().split()))
notFound = []
notFoundIndex = []
result = [0 for i in range(test_n)]
for i in range(len(sequence)):
if len(notFound) > 0:
for j in range(len(notFound)-1,-1,-1):
if notFound[j] < sequence[i]:
result[notFoundIndex[j]] = sequence[i]
notFound.pop()
notFoundIndex.pop()
else:
break
notFound.append(sequence[i])
notFoundIndex.append(i)
for i in notFoundIndex:
result[i] = -1
print(' '.join(map(str,result)))
import sys
n = int(sys.stdin.readline())
sequence = list(map(int,sys.stdin.readline().strip().split()))
notFound = []
result = [-1] * n
for i in range(n):
while len(notFound) > 0 and sequence[notFound[-1]] < sequence[i]:
result[notFound.pop()] = sequence[i]
notFound.append(i)
print(' '.join(map(str,result)))
4. Learned