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 |
我凌乱了。过了discuss里面所有的测试数据。。为什么还是WA...#include <stdio.h> #include <string.h> //函数声明 int getdot(char str[]); void clearleft(); long clearright(); void multi(char str[],int n); void print(long len); void cheng(long str1[],long str2[]); char str1[1000]; long n,a1,dotlocal; long s1[1000],s2[1000],c[1000]; int main() { //定义变量 while (scanf("%s %d",str1,&n)!=-1) { if (str1[strlen(str1)-1]=='.') str1[strlen(str1)-1]='\0'; clearleft(); dotlocal=getdot(str1); if (dotlocal!=0) { long i=strlen(str1)-dotlocal-1; a1=clearright(); dotlocal-=a1; if (dotlocal==0) { str1[strlen(str1)-1]='\0'; if (strlen(str1)==0) { printf("0\n"); continue; } } else { for (;i<6;i++) str1[i]=str1[i+1]; str1[i]='\0'; } } //printf("%s",str1); //system("pause"); dotlocal*=n; multi(str1,n); print(dotlocal); } return 0; } int getdot(char str[]) //获得小数点的位置 { int i,len=strlen(str); for (i=0;i<len-1;i++) { if (str[i]=='.') return (strlen(str)-i-1); } return 0; } void clearleft() //去除字符串左边的0 { int i,j; for (i=0;i<6;i++) if (str1[i]!='0') break; for (j=0;j<6;j++) str1[j]=str1[j+i]; } long clearright() //右边的0 { int len=strlen(str1); int len1=len; while (str1[len-1]=='0') len--; str1[len]='\0'; return len1-len; } void multi(char str[],int n) { long a[100],sum,i,j; for (i=0;i<=1000;i++) { s1[i]=0; s2[i]=0; } sum=-1; while (n>0) { a[++sum]=n%2; n=n/2; } for (i=0;i<strlen(str);i++) s1[i+1]=str[strlen(str)-i-1]-48; s1[0]=strlen(str); //for (i=1;i<=strlen(str);i++) //printf("%d ",s1[i]); //system("pause"); //str1:=str; @pascal if (a[0]==1) { int i=0; for ( ;i<=s1[0];i++) s2[i]=s1[i]; } else { s2[0]=1; s2[1]=1; } for (i=1 ;i<=sum;i++) { cheng(s1,s1); s1[0]=c[0]; for (j=1;j<=c[0];j++) s1[j]=c[j]; if (a[i]==1) { cheng(s2,s1); s2[0]=c[0]; for (j=1;j<=c[0];j++) s2[j]=c[j]; } } } void cheng(long str1[],long str2[]) { int a[1000],b[1000],i,j; a[0]=str1[0];b[0]=str2[0]; for (i=1;i<=a[0];i++) a[i]=str1[i]; for (i=1;i<=b[0];i++) b[i]=str2[i]; for (i=1;i<=1000;i++) c[i]=0; for (i=1;i<=a[0];i++) for (j=1;j<=b[0];j++) { c[i+j-1]+=a[i]*b[j]; c[i+j]+=c[i+j-1]/10; c[i+j-1]%=10; } c[0]=a[0]+b[0]; while ((c[c[0]]==0) && (c[0]>1)) c[0]--; } void print(long len) { int i=0; if (s2[0]>len) { for ( ;i<s2[0]-len;i++) printf("%c",s2[s2[0]-i]+48); } if (dotlocal!=0) printf("."); i=0; if (s2[0]<len) { for ( ;i<len-s2[0];i++) printf("0"); len=s2[0]; } for (i=len;i>0;i--) printf("%c",s2[i]+48); printf("\n"); // system("pause"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator