HUST Online Judge WebBoard
Problem 4112 >> 答案错误,但是在VC上答案都是对的
201803010212 @ 2019-06-07 10:19:06
[ Quote ] [ Edit ] [ Delete ] 1#
#include<stdio.h>
#include<string.h>
#include<math.h>
int jinzhi1(char a[])
{
int m,i,t=0,sum=0;
m=strlen(a);
for(i=m-1;i>=0;i--)
{
if(a[i]<='9'&&a[i]>='0')
{
sum=sum+(a[i]-48)*pow(16,t);
t++;
}
if(a[i]=='A')
{
sum=sum+10*pow(16,t);
t++;
}
if(a[i]=='B')
{
sum=sum+11*pow(16,t);
t++;
}
if(a[i]=='C')
{
sum=sum+12*pow(16,t);
t++;
}
if(a[i]=='D')
{
sum=sum+13*pow(16,t);
t++;
}
if(a[i]=='E')
{
sum=sum+14*pow(16,t);
t++;
}
if(a[i]=='F')
{
sum=sum+pow(16,t);
t++;
}
}
return sum;
}
int jinzhi2(int n)
{
int j,sum=0,t=0;
while(n)
{
j=n%8;
n=n/8;
sum=sum+j*pow(10,t);
t++;
}
return sum;
}
int main()
{
char a[100010];
int n,i,j,m,k;
scanf("%d",&n);
for(k=0;k<n;k++)
{
scanf("%s",a);
i=jinzhi1(a);
j=jinzhi2(i);
printf("%d\n",j);
}
return 0;
}
admin @ 2019-06-09 14:19:21
[ Quote ] [ Edit ] [ Delete ] 2#
大数,你用int存结果,肯定会炸。