#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
typedef int Status;
typedef int ElemType;
typedef int SElemType;
typedef struct StackNode
{
ElemType data;
struct StackNode *next;
}StackNode,*LinkStack;
LinkStack S;
Status InitStack(LinkStack &S)
{
S = NULL;
return OK;
}
bool StackEmpty(LinkStack S)
{
if(S==NULL)
return OK;
else
return ERROR;
}
Status Push(LinkStack &S,SElemType e)
{
LinkStack p;
p = new StackNode;
p->data = e;
p->next = S;
S = p;
return OK;
}
Status Pop(LinkStack &S,SElemType &e)
{
LinkStack p;
if(S==NULL) return ERROR;
e=S->data;
p=S;
S=S->next;
delete p;
return OK;
}
void conversion(int N,int R)
{
LinkStack S;
InitStack(S);
int e;
while(N){
Push(S,N%R);
N=N/R;
}
while(!StackEmpty(S))
{
Pop(S,e);
printf("%d",e);
}
}
int main()
{
int N,R;
printf("请输入你要转换的数:");
scanf("%d",&N);
printf("请输入你要转换的进制:");
scanf("%d",&R);
conversion(N,R);
return 0;
}