본문 바로가기
백준

[2493] 탑

by Jcoder 2018. 10. 20.


#include <iostream>
#include <stack>
using namespace std;
int main()
{
int n, t, i;
stack<pair<int, int> > st;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d", &t);
while (!st.empty())
{
if (st.top().second > t)
{
printf("%d ", st.top().first);
break;
}
st.pop();
}
if (st.empty())
printf("0 ");
st.push(make_pair(i, t));
}
}


'백준' 카테고리의 다른 글

[2231] 분해합  (0) 2018.10.20
[2309] 일곱 난쟁이  (0) 2018.10.20
[2959] 거북이  (0) 2018.10.19
[1813] 마지막 한마디  (0) 2018.10.19
[1834] 나머지와 몫이 같은 수  (0) 2018.10.19