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 |
那位大牛帮忙看看错哪了 1001#include<stdio.h> #include<string.h> const int MAX=7; const int mbit=500; char mul[MAX]; char mutp[mbit]; char result[mbit]; int n; int dot; int dotbit; int main() { while(scanf("%s%d",mul,&n)!=EOF) { int i,j; dotbit=0; for(i=0;mul[i]!='\0';i++) { if(mul[i]=='.') { dotbit=5-i; break; } } if(n==0) { printf("1\n"); continue; } if(n==1) { printf("%s\n",mul); continue; } memset(result,0,sizeof(result)); memset(mutp,0,sizeof(mutp)); dotbit=dotbit*n; if(dotbit==0) dot=5; else dot=4; for(i=0,j=5;j>=0;j--) { if(mul[j]!='.') mutp[i++]=mul[j]; } for(i=0,j=0;mutp[i]!=0;i++) mul[j++]=mutp[i]; //printf("%s %s\n",mul,mutp); while(n-1>0) { for(i=0;i<=dot;i++) { int c=0; for(j=0;mutp[j]!=0;j++) { if(result[i+j]==0) { int cc=((mul[i]-48)*(mutp[j]-48)+c)/10; result[i+j]=((mul[i]-48)*(mutp[j]-48)+c)%10+48; c=cc; } else { int cc=((result[i+j]-48)+(mul[i]-48)*(mutp[j]-48)+c)/10; result[i+j]=((result[i+j]-48)+(mul[i]-48)*(mutp[j]-48)+c)%10+48; c=cc; } } if(c!=0) result[i+j]=c+48; } //printf("%s\n",result); strcpy(mutp,result); memset(result,0,sizeof(result)); n--; } //printf("%s\n",mutp); int count=0; for(i=0;mutp[i]!=0;i++) count++; //printf("%d\n",count); bool mark=false; int s=-1; for(i=0;i<count;i++) if(mutp[i]!='0') { s=i; break; } bool flag=false; if(dotbit==0) { for(i=count-1;i>=0;i--) { if(mutp[i]!='0') flag=true; if(flag) printf("%c",mutp[i]); } } else for(i=count-1;i>=s;i--) { if(mutp[i]!='0'||i==dotbit-1) flag=true; if(flag) { if(i!=(dotbit-1)) printf("%c",mutp[i]); else {printf(".");printf("%c",mutp[i]);} } } 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