呃呃,看看就好,不用多说......
代码实现
#include <iostream>
#define ElemType int
#define MAXSIZE 100
using namespace std;
struct likestack
{
int top;
ElemType date[MAXSIZE];
};
void initstack(likestack *S)
{
S->top=-1;
}
bool push(likestack *S,ElemType e)
{
if(S->top==MAXSIZE-1)
{
return false;
}
S->top++;
S->date[S->top]=e;
return true;
}
bool stackempty(likestack *S)
{
if(S->top==-1)
{
return true;
}
else
{
return false;
}
}
bool pop(likestack *S,ElemType *e)
{
if(S->top==-1)
{
return false;
}
*e=S->date[S->top];
S->top--;
return true;
}
int main()
{
int n,m,f;
char c='A';
likestack *S=new likestack;
initstack(S);
cin>>n>>m;
while(n!=0)
{
f=n%m;
push(S,f);
n=n/m;
}
while(stackempty(S)!=true)
{
pop(S,&f);
if(f>=10)
cout<<char(c+f-10);//这注意一下,还是有点巧妙的
else
cout<<f;
}
return 0;
}