Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
输出
示例输入
7 2 23 12 -4 3
示例输出
1111B-11
哎。。之前我做的时候,我感觉自己没有用桟,还觉得自己无比手残,现在想想挺搞笑的,这个题就是一直取余,然后把所有的结果逆序输出,当遇到大于10的时候,在输出所对应的字母。
[code=c/c++]
#include<stdio.h>
int main()
{
int x,y;
int z[1000];
while(scanf("%d%d",&x,&y)!=EOF)
{
if(y<2||y>16) break;
int t=x;
if(x==0)printf("0\n");
else
{
if(x<0)
{
x=-x;
}
int i=0,m=0;
while(x>0)
{
z[i++]=x%y;
x=x/y;
m++;
}
if(t<0)printf("-");
for(i=m-1; i>=0; i--)
{
if(z[i]==10) printf("A");
else if(z[i]==11) printf("B");
else if(z[i]==12) printf("C");
else if(z[i]==13) printf("D");
else if(z[i]==14) printf("E");
else if(z[i]==15) printf("F");
else printf("%d",z[i]);
}
}
printf("\n");
}
return 0;
}
[/code]