top of page

소스 코드 제출

공개·회원 50명

20250807

/*

#include <stdio.h>

#include <string.h>


char stack[50001]= {};

int top=-1;


void push(char a)

{

top++;

stack[top]=a;

}


void pop()

{

top--;

}


int main()

{

char c[50001]= {};

scanf("%s",c);


for(int i=0; c[i]!=0; i++)

{

if(c[i]=='(')

{

push(c);

}

else if(c[i]==')')

{

pop();

if(top<-1)

{

printf("bad");

return 0;

}

}

}


// 삼항연산자 조건식?a:b

printf( top==-1 ? "good" : "bad");

return 0;

}

*/


//STL stack

#include <stdio.h>

#include <string.h>

int stack[200]={};

int ttop=-1;


void push(char a)

{

ttop++;

stack[ttop]=a;

}


void pop()

{

if(ttop>-1)

{

ttop--;

}

}


void top()

{

if(ttop==-1)

{

printf("-1\n");

}

else

{

printf("%d\n", stack[ttop]);

}

}


void size()

{

printf("%d\n", ttop+1);

}


void empty()

{

if(ttop==-1)

{

printf("true\n");

}

else

{

printf("false\n");

}

}


int main()

{

int n;

char c[201]={};

scanf("%d",&n);


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

{

gets(c);

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

{

push(c[6]-'0');

}

else if(c[0]=='p' && c[1]=='o')

{

pop();

}

else if(c[0]=='t')

{

top();

}

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

{

size();

}

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

{

empty();

}

}


return 0;

}

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