十进制转换任意进制。
/*
HDU 2031 十进制转换任意进制
AC by J_Dark
Time 0ms
ON 2013/5/18
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
char alpha[6] = {'A','B','C','D','E','F'};
string Res;
int fromBase = 10;
int num, toBase;
//
int main(){
while(cin >> num >> toBase)
{
bool zeng = true;
if(num < 0){
zeng = false;
num = -num;
}
Res.clear();
int i=0;
while(num != 0)
{
int temp = num%toBase;
if(temp > 9)
Res[i++] = alpha[temp%10];
else
Res[i++] = temp + '0';
num /= toBase;
}
if(!zeng)
cout << "-";
for(int j=i-1; j>=0; j--)
cout << Res[j];
cout << endl;
}
return 0;
}