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 |
搞出来了!绝对是自己写的!附上讲解!#include <stdio.h> #include <string.h> #define M 1000 int l,c[10][M];c数组用于错位 void cf(int a[],int b,int t) { int i,length,sum,d,j,temp,k; for(length=999;;) if(a[length]==0) length--; else break; d=0; for(i=0,j=t;i<=length;i++,j++) { sum=a[i]*b+d; d=sum/10; c[t][j]=sum%10; } while(d!=0) { c[t][j++]=d%10; d/=10; } k=j-1; for(i=0;i<j;i++,k--) { temp=c[t][i]; c[t][i]=c[t][k]; c[t][k]=temp; } //for(i=0;i<j;i++) //printf("%d",c[t][i]); //printf("\n"); } void add(int a[])//将每一位所得的乘相加并付给数组a { int i,j,ml=0,sum,d,len,flag; for(i=0;i<l;i++) { flag=0; for(len=999;;len--) { if(c[i][len]) flag=1; if(flag) break; } if(len>ml) ml=len; } //printf("%d\n",ml); memset(a,0,sizeof(a)); d=0; for(j=0;j<=ml;j++) { sum=0; for(i=0;i<l;i++) sum+=c[i][j]; sum+=d; d=sum/10; a[j]=sum%10; } while(d) { a[j++]=d%10; d/=10; } //printf("%d\n",j); //for(i=0;i<j;i++) //printf("%d",a[i]); //printf("\n"); memset(c,0,sizeof(c)); } void mulit(int a[],int b[]) { int i; for(i=0;i<l;i++) cf(a,b[i],i);//数组b是储存R 取出每一位与a相乘 add(a); } int main() { int a[1000],b[10],i,j,length,times,k,index,flag,f; char str[10]; while(scanf("%s %d",str,×)!=EOF) { length=strlen(str); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(k=length-1;k>=0;k--) if(str[k]!='0') break; index=0; flag=0; f=0; for(i=k,j=0;i>=0;i--) { if(str[i]=='.') { flag=1; for(k=i-1;k>=0;k--) if(str[k]!='0') f=1; } if(str[i]!='.') { a[j]=str[i]-'0'; b[j]=a[j]; j++; if(!flag) index++; } } l=j; index=index*times; index--; times--; while(times--) mulit(a,b); for(length=999;;length--) if(a[length]) break; if(f) { for(i=length;i>index;i--) printf("%d",a[i]); if(index>0) { printf("."); for(;i>=0;i--) printf("%d",a[i]); } } else { printf("."); for(i=index;i>=0;i--) printf("%d",a[i]); } printf("\n"); } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator