문제 링크: https://www.acmicpc.net/problem/17299
백준 알고리즘 기초 1/2 201에서 4번째 - 17299번 오등큰수를 풀어보았다.
풀이: 오큰수에 등장 횟수를 적용시키면 된다.
C++
Python
from collections import Counter
n=int(input())
inp=list(map(int,input().split()))
stack=[]
res=[-1 for i in range(n)]
cnt=Counter(inp)
for i in range(n):
while stack and cnt[inp[stack[-1]]]<cnt[inp[i]]:
res[stack.pop()]=inp[i]
stack.append(i)
print(*res)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
후위 표기식 풀이 (0) | 2023.01.10 |
---|---|
후위 표기식2 풀이 (0) | 2023.01.10 |
오큰수 풀이 (0) | 2023.01.10 |
쇠막대기 풀이 (0) | 2023.01.10 |
단어 뒤집기 2 풀이 (0) | 2023.01.10 |