杭電oj 2031

Problem Description

輸入一個十進制數N,將它轉換成R進制數輸出。

 

 

Input

輸入數據包含多個測試實例,每個測試實例包含兩個整數N(32位整數)和R(2<=R<=16, R<>10)。

 

 

Output

爲每個測試實例輸出轉換後的數,每個輸出佔一行。如果R大於10,則對應的數字規則參考16進制(比如,10用A表示,等等)。

 

 

Sample Input


 

7 2 23 12 -4 3

 

 

Sample Output


 

111 1B -11

 

/*
string str 當數組用 ,s.insert(s.begin(),i) ,在頭處插 
*/ 

/*
string str 當數組用 ,s.insert(s.begin(),i) ,在頭處插 
*/ 
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main(void)
{
    string str="0123456789ABCDEF";
    int n,m;
    while(cin>>n>>m){
        string s;
        if(n<0)cout<<"-";
        n=abs(n);
        while(n){
            s.insert(s.begin(),str[n%m]);
            n/=m;
        }
        cout<<s<<endl;
    }
    return 0;
}

 

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