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嘛?为何总是WA,有无更变态的数据,或哪位大侠给指下我的程序错误!(附code)#include<stdio.h> typedef struct { int data[1000]; int length; }Bigint; Bigint multi(Bigint a,Bigint b) { int i,j,k; int arr[1000]; int brr[1000]; int cm,cs;//乘法进位,加法进位 int temp; int lang,leng; int stack; for(i=0;i<1000;i++) { arr[i]=0; brr[i]=0; } lang=a.length; //进行乘法 for(i=0;i<b.length;i++) { temp=0; cm=0; for(j=a.length-1;j>=0; j--) { brr[temp]=(a.data[j]*b.data[i]+cm)%10; cm=(a.data[j]*b.data[i]+cm)/10; temp++; } if(cm>0) { brr[temp]=cm; temp++; if(i==0) lang++; } //进行加法 cs=0; for(k=0;k<temp;k++) { stack=(arr[k]+brr[k]+cs)%10; cs=(arr[k]+brr[k]+cs)/10; arr[k]=stack; } while(cs>0) { stack=(arr[k]+cs)%10; cs=(arr[k]+cs)/10; arr[k]=stack; k++; } //进行移位 if(i<b.length-1) { for(k=lang-1;k>=0;k--) arr[k+1]=arr[k]; arr[0]=0; lang++; } } a.length=lang; leng=a.length-1; for(i=0 ;i<a.length;i++) { a.data[leng]=arr[i]; leng--; } return a; } void main() { int i; int index; int flag; Bigint num1,num2,num3; char strs[10],radix; int dot; int first,last; int count; while(scanf("%s%d",strs,&radix)!=EOF) { for(i=0;i<1000;i++) { num1.data[i]=0; num2.data[i]=0; } index=0; num1.length=0; flag=0;//判断输入中是否有点 while(strs[index]!='\0') { num1.data[num1.length]=strs[index]-'0'; if(strs[index]=='.') { dot=index; flag=1; index++; } else { index++; num1.length++; } } if(flag==1) dot=(index-dot-1)*radix; else dot=0; num2=num1; for(i=0;i<radix-1 ;i++) { num3=num1; num1=multi(num3,num2); } flag=0; first=0; last=0; count=0; for( i=0 ;i<num1.length ; i++) count+=num1.data[i]; for(i=0;i<num1.length-dot;i++) { if(num1.data[i]==0 && flag==0) first++; else if(num1.data[i]!=0) flag=1; } flag=0; for(i=num1.length-1;i>=num1.length-dot;i--) { if(num1.data[i]==0 && flag==0) last++; else if(num1.data[i]!=0) flag=1; } if(count==0) printf("0"); else if(radix==0) printf("1"); else { if(dot>num1.length) { printf("."); for(i=first;i<num1.length-last;i++) { if(dot>num1.length) { printf("0"); dot--; i--; } else printf("%d",num1.data[i]); } } else { for(i=first;i<num1.length-last;i++) { if(i==num1.length-dot) printf(".%d",num1.data[i]); else printf("%d",num1.data[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