Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我确实不知道哪儿错了~~麻烦哪位大侠给指点指点~到底还要考虑什么细节啊?In Reply To:我确实不知道哪儿错了~~麻烦哪位大侠给指点指点~到底还要考虑什么细节啊? Posted by:luketyg at 2009-01-11 17:52:44 > #include "iostream" > using namespace std; > void Mul(char *s1, char *s2, char *Ans) > { > int a[100]={0},b[100]={0},c[256]={0}; > int Len1=strlen(s1),Len2=strlen(s2),Len=Len1+Len2,k=0,x,y,z,i,j,w; > for(i=Len1-1;i>=0;i--) > a[++k]=s1[i]-'0'; > k=0; > for(i=Len2-1;i>=0;i--) > b[++k]=s2[i]-'0'; > for(i=1;i<=Len1;i++) > for(j=1;j<=Len2;j++) > { > x=a[i]*b[j]; > y=x/10; > z=x%10; > w=i+j-1; > c[w]=c[w]+z; > c[w+1]=c[w+1]+c[w]/10+y; > c[w]=c[w]%10; > } > while(c[Len]==0 && Len>1) Len--; > k=0; > for(i=Len;i>=1;i--) > Ans[k++]=c[i]+'0'; > Ans[k]='\0'; > } > int main() > { > char r[6]; > int n; > while(scanf("%s %d",r,&n)!=EOF) > { > int i,index,j; > for(i=0;i<6;i++) > { > if(r[i]=='.') > { > index=i; > for(j=i;j<5;j++) > r[j]=r[j+1]; > r[j]='\0'; > break; > } > } > char c[256]; > if(n==0) > cout<<1<<endl; > else > { > Mul(r,r,c); > for(i=2;i<n;i++) > Mul(r,c,c); > int w=(5-index)*n; > if(w==0)cout<<c<<endl; > if(w>=strlen(c)) > { > for(j=strlen(c)-1;j>=0;j--) > if(c[j]!='0')break; > if(j==-1)cout<<0<<endl; > else > { > cout<<"."; > for(i=0;i<w-strlen(c);i++) > cout<<0; > for(i=0;i<=j;i++) > cout<<c[i]; > cout<<endl; > } > } > else > { > for(j=strlen(c)-1;j>=0;j--) > if(c[j]!='0')break; > for(i=0;i<strlen(c)-w;i++) > cout<<c[i]; > if(i!=j+1) > { > cout<<"."; > for(;i<=j;i++) > cout<<c[i]; > } > cout<<endl; > } > } > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator