top of page

소스 코드 제출

공개·회원 50명

20250711

/*

#include <stdio.h>

int node(int a,int b,int n)

{

if(a==b)

{

return n;

}

if(a>b)

{

a=a/2;

n++;

}

else

{

b=b/2;

n++;

}

return node(a,b,n);

}

int main()

{

int a,b,n=0;

scanf("%d %d",&a,&b);

if(a==b)

{

printf("0");

return 0;

}

printf("%d",node(a,b,n));

return 0;

}

data structure


Stack : 쌓는거

-> Last In First Out : LIFO 구조

*/

/*

#include <stdio.h>

int stack[100]={};

int top = 0;

void push(int data)

{

stack[top] = data;

top++;

}

int main()

{

int i, a;

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

{

scanf("%d",&a);

if(a!=0)

{

push(a);

}

else

{

if()

{

top--; // pop할때는, 스택에 데이터가 없을때실행되지 않도록!!!

}


}

}

printf("stack [ ");

for(i=0;i<=top-1;i++)

{

printf("%d ",stack[i]);

}

printf("]");

}

*/


#include <stdio.h>

int main()

{

int stack[100000]={};

int top = 0;

int a, b, c;

int i;

while(1)

{

printf("[ menu ] 1. push 2. pop 3. view >>");

scanf("%d",&a);

if(a==1)

{

printf("push할 데이터 입력하세요>> ");

scanf("%d",&b);

stack[top]=b;

top++;

}

else if(a==2)

{

if(top-1>-1)

{

top--;

}

}

else if(a==3)

{

printf("\n");

for(i=0;i<=top-1;i++)

{

printf("%d ",stack[i]);

}

printf("\n");

}


}

return 0;

}

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