十進制數轉化爲任意進制數


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#define MAX 1005
using 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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章