Skip to content

Instantly share code, notes, and snippets.

@ajuanhuang
Created December 7, 2012 14:52
Show Gist options
  • Save ajuanhuang/4233734 to your computer and use it in GitHub Desktop.
Save ajuanhuang/4233734 to your computer and use it in GitHub Desktop.
2到16进制转换
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,f=0,k=0,n,p,p1,r1,g,q,q1,r,s1=0,s2=0,s3=0,b[1000];
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&q,&p,&r);
for(j=2;j<=16;j++)
{
q1=q;k=0;
while(q1!=0&&q1%10<j)
{
s1=s1+(q1%10)*pow(j,k);
q1=q1/10;
k++;
}if(q1!=0)
s1=1;p1=p;k=0;
while(p1!=0&&p1%10<j)
{
s2=s2+(p1%10)*pow(j,k);
p1=p1/10;
k++;
}if(p1!=0)
s2=0;r1=r;k=0;
while(r1!=0&&r1%10<j)
{
s3=s3+(r1%10)*pow(j,k);
r1=r1/10;
k++;
}if(r1!=0)
s3=1;
if(s1*s2==s3)
{
b[f]=j;
f++;
}s1=0;s2=0;s3=0;
}if(f!=0)
{
printf("%d\n",b[0]);b[0]=0;f=0;
}
else
printf("0\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment