shiyan

JUVBUFFON / 2024-12-19 / 原文

#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct{
ElemType *base;
ElemType *top;
int ssize;
}sq;
void createS(sq &S)
{
S.base=(ElemType*)malloc(100*sizeof(ElemType));
S.top=S.base;
S.ssize=100;
}

void getS(sq S,ElemType &e)
{
e=*(S.top-1);
}

void pushS(sq &S,ElemType e)
{
*S.top++=e;
}

void popS(sq &S,ElemType &e)
{
e=*--S.top;
}

void change(int n,int a)
{
sq S;
createS(S);
int N=n;
while(N)
{
pushS(S,N%a);
N=N/a;
}
while(S.top!=S.base)
{
int e;
popS(S,e);
printf("%d",e);
}
}

int main()
{
int n,a;
scanf("%d %d",&n,&a);
change(n,a);
return 0;
}