백준 문제풀이

백준 17298번 - C++

diligent_gideok 2022. 4. 30. 06:21
#include <bits/stdc++.h>
using namespace std;


int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	stack<int> S;
	int A[100002] = { };
	int n;
	cin >> n;
	

	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		if (S.empty()) {
			S.push(m);
			continue;
		}
		while (S.top() < m) {
			A[S.top()] = m;
			S.pop();
		}
		S.push(m);
	}
	cout << A;
	
}