#include<iostream>
#include<stack>
using namespace std;
int main(){
int n,m;
stack<char> st;
while(cin>>n>>m){
int temp;
if((n<0&&m>0)||(n>0&&m<0))
cout<<"-";
while(n){
temp=n%m;
temp=temp>0?temp:-temp;
if(temp>=10)
st.push(temp-10+'A');
else
st.push(temp+'0');
n/=m;
}
while(!st.empty()){
cout<<st.top();
st.pop();
}
cout<<endl;
}
return 0;
}
转载于:https://blog.51cto.com/beyond316/1272552