数学问题——十进制转N进制

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

char intToChar(int n){
    if(n < 10){
        return n + '0';
    }else{
        return n - 10 + 'A';
    }
}

void convert(int n,int k){
    vector<int> answer;
    
    while(n != 0){
        answer.push_back(intToChar(n % k));
        n /= k;
    }
    for(int i = answer.size() - 1;i >= 0;i-- ){
        printf("%c",answer[i]);
    }
    printf("\n");
}

int main(){
    int n,k;
    while(scanf("%d%d",&n,&k) != EOF){
        convert(n,k);
    }
    return 0;
}

 

posted @ 2020-05-15 20:43  天凉好个秋秋  阅读(206)  评论(0编辑  收藏  举报