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> void add(char s1[1000],char s2[1000]); void switchstr(char s[1000],int length); char sumstr[1000]; void main() { char R1[1000],R[1000],r[1000],ride[1000],sum[1000],sumts[1000]; int n; int carry,mend; int i,t,a,b; int length,lengthg,ttt; while(scanf("%s%d",R,&n)!=0) { if(strcmp(R,"0.0000")>0&&strcmp(R,"99.999")<0&&n>0&&n<=25) { strcpy(sum,R); length=strlen(R); for(i=0;i<length;i++) if(R[i]=='.') { ttt=(length-i-1)*n; break; } if(i==length) ttt=0; n--; while(n--) { a=strlen(sum); strcpy(ride,"0"); mend=0; while(a--) if(sum[a]!='.') { carry=0;t=0;b=strlen(R); for(i=0;i<mend;i++) r[t++]='0'; mend++; while(b--) if(R[b]!='.') { r[t++]=((sum[a]-48)*(R[b]-48)+carry)%10+48; carry=((sum[a]-48)*(R[b]-48)+carry)/10; } if(carry!=0) r[t++]=carry+48; r[t]='\0'; switchstr(r,strlen(r)); add(ride,r); strcpy(ride,sumstr); } strcpy(sum,ride); }//while lengthg=strlen(sum);t=0; for(i=0;i<lengthg;i++) { if(i==(lengthg-ttt)) sumts[t++]='.'; sumts[t++]=sum[i]; } sumts[t]='\0'; t=0;length=strlen(sumts); for(i=0;i<length;i++) { if(sumts[i]=='0'&&t==0) continue; R1[t++]=sumts[i]; } // printf("%d\n",length); while(R1[--t]=='0'&&ttt>0) ttt--; if(R1[t]=='.') t--; R1[++t]='\0'; if(strlen(R1)==0) strcpy(R1,"0"); printf("%s\n",R1); } else printf("input error."); } }//main void add(char s1[1000],char s2[1000]) { int length1,length2; int carry,t; length1=strlen(s1); length2=strlen(s2); carry=0;t=0; while(length1&&length2) { length1--;length2--; sumstr[t++]=(s1[length1]+s2[length2]-96+carry)%10+48; carry=(s1[length1]+s2[length2]-96+carry)/10; } while(length1) { length1--; sumstr[t++]=(s1[length1]-48+carry)%10+48; carry=(s1[length1]-48+carry)/10; } while(length2) { length2--; sumstr[t++]=(s2[length2]-48+carry)%10+48; carry=(s2[length2]-48+carry)/10; } if(carry!=0) sumstr[t++]=carry+48; sumstr[t]='\0'; switchstr(sumstr,strlen(sumstr)); } void switchstr(char s[1000],int length) { int i; char temp; for(i=0;i<length/2;i++) { temp=s[i]; s[i]=s[length-1-i]; s[length-1-i]=temp; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator