Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:为什么还是wrong answer?

Posted by A0317308 at 2004-02-11 00:20:21 on Problem 1001
In Reply To:为什么还是wrong answer? Posted by:geniusxsy at 2003-12-15 17:49:14
 while(a!=(float)((int)a))  /*把a转为long型,存为al,并求小数位数k*/
 {a*=10;k++;
 }
以上部分有问题,当a=5.1234与a=5.1232时,k值一个等于7,一个等于4。看来不能用这种强制转换的方法。






> 难道fun部分有问题?我下午在UNIX上调过的,现在凭记忆写出来(只把原来int b[150]改为short了),难道写错了?不会啊!大家帮忙看一下,谢谢!
> 
> void fun(float a,int n)
> { long al,temp1,temp2;
>  short b[150]={0};       /*存放结果的数组*/
>  int i,j,k=0;
>  short *p;p=b;
>     while(a!=(float)((int)a))  /*把a转为long型,存为al,并求小数位数k*/
>  {a*=10;k++;
>  }
>  k=k*n;     /*n次方的小数位数*/
>  al=(int)a;                     
>  b[149]=1;    
>  for(i=0;i<n;i++)
>  { temp2=0;
>     for(j=149;j>=0;j--)
>       { temp1=b[j]*al+temp2;   /*求某位数乘以al后再加后一位进位进上来的数*/
>         b[j]=temp1%10;         
>         temp2=temp1/10;        /*往前进位的数*/
>        }
>   }
>   while(*p==0&&p<b+149-k) p++;  /*处理掉前面多余的0*/
>   for(;p<b+150-k;p++)
>   printf("%d",*p);
>   printf(".");
>   for(;p<b+150;p++)
>   printf("%d",*p);
> }
> 
> main()
> {float a;int n; 
>   while(scanf("%f%d",&a,&n)==2)
>   { fun(a,n);}
> }
>  

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator