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 |
这个程序总是wa,求指点……#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; char *cheng(char s1[],char s2[]) { int l1,l2,l,i,j,r,a[300],b[300],c[300]; char data[300]; memset(c,0,sizeof(c)); memset(data,0,sizeof(data)); l1=strlen(s1); l2=strlen(s2); l=l1+l2-1; for (i=0; i<=l1-1; i++) a[l1-i]=s1[i]-'0'; for (i=0; i<=l2-1; i++) b[l2-i]=s2[i]-'0'; for (i=1;i<=l1;i++) for (j=1;j<=l2;j++) c[i+j-1]+=a[i]*b[j]; r=0; for (i=1;i<=l;i++) { c[i]=c[i]+r; r=c[i]/10; c[i]%=10; } if (r>0) { l++; c[l]=r; } for (i=1; i<=l; i++) data[l-i]=c[i]+'0'; return data; } int main() { char s1[300],s2[300]; char s3[300]; int n,sum,all,i,l,j; memset(s1,0,sizeof(s1)); while (scanf("%s %d",s1,&n)==2) { memset(s2,0,sizeof(s2)); memset(s3,0,sizeof(s3)); l=strlen(s1);sum=0; for (i=l-1;i>=0;i--) if (s1[i]!='.') sum++; else break; if (sum==l) all=0; else all=n*sum; if (all!=0) { for (i=0;i<=l-1-sum-1;i++) s2[i]=s1[i]; for (i=l-sum;i<=l-1;i++) s2[i-1]=s1[i]; } else strcpy(s2,s1); strcpy(s3,s2); for (i=1;i<=n-1;i++) { strcpy(s3,cheng(s3,s2)); } i=strlen(s3); while (s3[i-1]=='0' && all>0 && i>0) { i--; all--; } if ((s3[i-all-1]=='0'&& i-all==1)==false) for (j=0;j<=i-all-1;j++) printf("%c",s3[j]); if (all!=0) printf("."); for (j=i-all;j<=i-1;j++) printf("%c",s3[j]); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator