任意进制转化
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int t,r,h;
int a[1000];
while(cin>>t>>r)
{
int i=0,ans=0,h=0;//多组输入初始化在内部
if(t<0){t=-t;h=1;}//h标记作用
while(t)
{
a[ans]=t%r;
t/=r;
ans++;
}
if(h)cout<<"-";//负数的处理
for(i=ans-1; i>=0; i--)
{
switch(a[i])
{
case 10:
cout<<'A';
break;
case 11:
cout<<'B';
break;
case 12:
cout<<'C';
break;
case 13:
cout<<'D';
break;
case 14:
cout<<'E';
break;
case 15:
cout<<'F';
break;
default :
cout<<a[i];
break;
}
}
cout<<endl;
}
return 0;
}