top of page

소스 코드 제출

공개·회원 52명

#include <stdio.h>

int stack[500001] = {};

int arr[500001] = {};

int top = -1;


void push(int a, int b)

{

top++;

stack[top] = a;

arr[top] = b;

}


void pop()

{

if (top > -1)

{

top--;

}

}


int main()

{

int n, h, i;

scanf("%d", &n);


for (i = 1; i <= n; i++)

{

scanf("%d", &h);


while (top > -1 && stack[top] < h)

{

pop();

}


if (top == -1)

{

printf("0 ");

}

else

{

printf("%d ", arr[top]);

}


push(h, i);

}


return 0;

}

4회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page