十进制数转化为任意进制数

来源:互联网 发布:游戏迷你主机知乎 编辑:程序博客网 时间:2024/05/22 16:02
#include <iostream>#include <stdio.h>#include <string.h>#include <vector>#include <algorithm>#include <queue>#include <stack>#define MAX 1005using namespace std;const int INF=0x3f3f3f3f;int n,m;int main(){    while(~scanf("%d%d",&n,&m)){        if(n==0)    printf("0\n");        stack<char> s;        while(n){            if(n%m>=10)                s.push('A'+n%m-10);            else                s.push('0'+n%m);            n=n/m;        }        while(!s.empty()){            printf("%c ",s.top());            s.pop();        }        printf("\n");    }    return 0;}
原创粉丝点击