#include#includetypedef struct{ int data[10025]; int top; int base;} seqstack;seqstack s;void seqstackinit(seqstack *s){ s->top=0; s->base=0;}void seqstackpush(seqstack &s,int k){ s.data[s.top]=k; s.top++;}int seqstackpop(seqstack &s,int k){ if(k<0 printf="" -="" s="" top--="" while="" s="" top="">=0) { if(s.data[s.top]>=10) { printf("%c",s.data[s.top]+55); } else { printf("%d",s.data[s.top]); } s.top--; } return 0;}int main(){ int n,m,k; while(~scanf("%d%d",&n,&m)) { if(n==0) { printf("0\n"); continue; } seqstackinit(&s); k=n; while(n) { if(n<0) { n=-n; } seqstackpush(s,n%m); n=n/m; } seqstackpop(s,k); printf("\n"); }}
进制转换(栈)
最新推荐文章于 2023-03-03 18:25:07 发布