//明白了一些道理。。
#include
#include
#include
#include
#define STACK_INIT_SIZE 100
#define STACKCREMENT 10
#define N 8
typedef struct
{
int *base;//栈底
int *top;//栈顶
int stacksize;//栈容量
}SqStack;
int InitStack(SqStack &S)
{
S.base=(int*)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S.base)
{
exit(0);
}
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return 1;
}
int Push(SqStack &S,int e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(int*)realloc(S.base,(S.stacksize+STACKCREMENT)*sizeof(int));
if(!S.base)
{
exit(0);
}
S.top=S.base+S.stacksize;
S.stacksize+=STACKCREMENT;
}
*S.top++=e;
return 1;
}
int StackEmpty(SqStack S)
{
if(S.top==S.base)
{
return 1;
}
return 0;
}
int Pop(SqStack &S,int &e)
{
if(S.top==S.base)
{
return 0;
}
e=*--S.top;
return 1;
}
int main()
{
int n,e;//n为要转换的十进制数,e为临时用的int变量
SqStack S;
InitStack(S);//构造一个空栈
scanf("%d",&n);
while(n)
{
Push(S,n%8);
n/=8;
}
while(!StackEmpty(S))
{
Pop(S,e);
printf("%d",e);
}
printf("\n");
return 0;
}