top of page

소스 코드 제출

공개·회원 77명

2025.04.13

/*#include <stdio.h>

int stack[80000],top=-1;

void push(int h)

{

stack[++top]=h;

}

void pop()

{

if(top!=-1)

stack[top--]=0;

}

int main()

{

int n,h,i,j;

long long int sum=0;

scanf("%d",&n);

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

{

scanf("%d",&h);

int c=0;

for(j=top;j>=0;j--)

{

if(stack[j]<=h)

pop();

else

c++;

}

sum+=c;

push(h);


}

printf("%lld",sum);

return 0;

}


스택 쌓는거 vs 큐


스택 큐

구조 후입선출(LIFO) 선입선출(FIFO)

push top++; front++;

pop top--; back++;

포인터 top(맨위데이터위치) back 마지막데이터위치 (=top)

front 마지막나간데이터의위치

empty? top==-1 front==back

*/

#include <stdio.h>

int queue[200]={},front=-1,back=-1;

void push(int x)

{

queue[++back]=x;

}

void pop()

{

if(front!=back)

front++;

}

void frontf()

{

if(front==back)

printf("-1\n");

else

printf("%d\n",queue[front+1]);

}

void backf()

{

if(back==front)

printf("-1\n");

else

printf("%d\n",queue[back]);

}

void size()

{

printf("%d\n",back-front);

}

void empty()

{

if(front==back)

printf("true\n");

else

printf("false\n");

}

int main()

{

char stl[21]="";

int n,i,j;

scanf("%d",&n);

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

{

gets(stl);

if(stl[1]=='u')

{

int k=0;

for(j=6;stl[j]!=32;j++)

k=k*10+stl[j]-48;

push(k);

}

else if(stl[1]=='o')

pop();

else if(stl[0]=='f')

frontf();

else if(stl[0]=='b')

backf();

else if(stl[0]=='s')

size();

else if(stl[0]=='e')

empty();

}

return 0;

}

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