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<iostream> #include<string> #define N 500 using namespace std; int c[N]={0}; int Length(int a[]); void Mul(int a[],int b[]); int main() { string R,s="99.999",t="0.0",p=".0"; int n , m , i ,j , point=0 , h=0; cin>>R>>n; for(i=R.length()-1;i>=0;i--)//判断是否有小数点 { if(R.at(i)=='.') { for(i=R.length()-1;i>=0;i--) { if(R.at(i)!='0') { i++; R=R.substr(0,i); break; } } h=1;//h=1说明有小数点 break; } } int length=R.length(); int a[N]={0},b[N]={0}; for(i=0,j=length-1-h;i<length;i++,j--)//把R去小数点存入 a; { if (R.at(i)=='.') { point=i+1; j++; } else a[j]=b[j]=R.at(i)-48; } if(h==1) point=length-point; else point=0; m=n-1; while(m) { Mul(a,b); for(i=Length(c)-1;i>=0;i--)//将a*b=c赋给b { b[i]=c[i]; c[i]=0; } m--; } if(Length(b)<point*n)//判断结果的位数是否大于小数点的位数不足补0 { cout<<'.'; for(i=point*n;i>Length(b);i--) cout<<0; } for(i=Length(b)-1;i>=0;i--) { if(i==(point*n-1))//输出小数点 { cout<<"."; point=0; i++; } else cout<<b[i]; } cout<<endl; return 0; } void Mul (int a[],int b[]) { int i , j , k , x , y , z; int length_a=Length(a); int length_b=Length(b); for( i=0;i<length_a;i++) { for(j=0;j<length_b;j++) { x=a[i]*b[j]; y=x/10; z=x%10; k=i+j; c[k]+=z; c[k+1]=c[k+1]+y+c[k]/10; c[k]=c[k]%10; } } k=length_a+length_b-1; if(c[k]==0)k--; } int Length(int a[]) { int i=N-1; while(!a[i]&&i>=0) i--; return i+1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator