/*1295. 负权数
*/
#include<iostream>
#include<memory.h>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main()
{
string n;
int N;
while(cin>>n && n != "#")
{
N = atoi(n.c_str());
int r;
cin>>r;
char display[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int mod[50];
if(N==0)
{
cout<<0<<endl;
}
else
{
int i=0;
while(N!=0)
{
int x=N/r;
int y=N-(x*r);
N=N/r;
if(y<0)
{
y=y+abs(r);
N++;
}
mod[i]=y;
i++;
}
for(int j=i-1;j>=0;j--)
{
cout<<display[mod[j]];
}
cout<<endl;
}
}
system("pause");
return 0;
}
1295. 负权数
最新推荐文章于 2017-09-10 12:46:37 发布