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:注意:用c的此题不可用strrev,系统会说你错的,所以自己写个strrev就过了,为了这个我付出10多此submition啊!In Reply To:Re:注意:用c的此题不可用strrev,系统会说你错的,所以自己写个strrev就过了,为了这个我付出10多此submition啊! Posted by:coryee at 2009-05-06 20:22:06 > 谢谢提醒 #include"stdio.h" #include"string.h" void f1(char str1[],char str2[]){ int sum[127][126]={0}; int len1=strlen(str1),len2=strlen(str2); int i,j; for(i=0;i<len2;i++){ for(j=0;j<len1;j++){ sum[i][j+i]+=((str2[i]-48)*(str1[j]-48))%10; sum[i][j+i+1]+=((str2[i]-48)*(str1[j]-48))/10; if(sum[i][j+i]>9) {sum[i][j+i+1]+=(sum[i][j+i]/10);sum[i][j+i]=(sum[i][j+i]%10);} } } for(i=0;i<len1+len2;i++){ for(j=0;j<len2;j++){ sum[126][i]+=sum[j][i]; if(sum[126][i]>9) {sum[126][i+1]+=sum[126][i]/10;sum[126][i]=sum[126][i]%10;} } } for(i=0;i<len1+len2;i++){ str1[i]=sum[126][i]+48; } if(str1[i-1]=='0') str1[i-1]='\0';else str1[i]='\0'; } void main(){ char str[126]; char strsouce[126]; int n; while(scanf("%s%d",&str,&n)==2){ int len,i,j=0,flag=0,f=0; if(n==1) {puts(str);continue;} len=strlen(str); //if(str[0]=='.') {str[j++]='0';len++;} for(i=0;i<len;i++){ if(str[i]!='0'||str[i+1]=='.') flag=1; if(str[i]=='.') f=(len-i-1)*n; if(flag==1&&str[i]!='.') str[j++]=str[i]; } str[j]='\0'; while(f!=0&&str[j-1]=='0'){ str[j-1]='\0';j--;f-=n; } strrev(str); strcpy(strsouce,str); for(i=2;i<=n;i++){ f1(str,strsouce); if(i==2&&n>=4){f1(str,str);i=4;} if(i==4&&n>=8){f1(str,str);i=8;} if(i==8&&n>=16){f1(str,str);i=16;} } strrev(str); len=strlen(str); for(i=0;i<len;i++){ //if(len-f<0&&i==0){printf(".");} if(len-f==1&&str[0]=='0'&&i==0){i++;} if(i==len-f) printf("."); printf("%c",str[i]); } printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator