解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 100
typedef struct
{
int data[MAXSIZE];
int top;
}SqStack;
int Empty(SqStack *S);
int PushStack(SqStack *S,int e);
int PopStack(SqStack *S,int *e);
void conversion(int number);
int Empty(SqStack *S)
{
if(S->top==-1)
return 1;
else
return 0;
}
int PushStack(SqStack *S,int e)
{
if(S->top==MAXSIZE-1)
return 0;
S->top++;
S->data[S->top]=e;
return 1;
}
int PopStack(SqStack *S,int *e)
{
if(S->top==-1)
return 0;
*e=S->data[S->top];
S->top--;
return 1;
}
void conversion(int number)
{
int e;
SqStack *L;
L->top=-1;
L=(SqStack *)malloc(sizeof(SqStack));
while(number)
{
PushStack(L,number%8);
number=number/8;
}
while(!Empty(L))
{
PopStack(L,&e);
printf("%d",e);
}
printf("\n");
}
int main()
{
int num;
while(scanf("%d",&num)!=EOF)
{
conversion(num);
}
return 0;
}
0.0分
0 人评分