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 |
怎么不能AC,测试数据都真确#include<iostream> #include<math.h> using namespace std; int W,D,O; int num(int a,int n); int * init(int a,int size); void cal(int *pa,int a,int n); void display(int *pa,int size,int n); int main() { int n; char b[7]; int a; while(cin>>b>>n) { a=0;D=0;W=0;O=0; char *p=b; while(*p!='.') {a=a*10+*p-48;p++;} char *q=p; while(*p!='\0') p++ ; p--; while(*p=='0') {p--;} *(p+1)='\0';q++; while(*q!='\0') {a=a*10+*q-48;q++;D++;} int size=num(a,n)+1; int *pa=init(a,size); cal(pa,a,n); display(pa,size,n); delete []pa; } getchar(); return 0; } int num(int a,int n) { double sum=1.0; sum=n*log10(a); return (int)sum; } int * init(int a,int size) { int*pa=new int[size]; int i=0; while(a>0) {pa[i++]=a%10;a/=10;W++;} for(int j=i;j<size;j++) pa[j]=0; return pa; } void cal(int *pa,int a,int n) { double end=W; int begin=0; for(int i=2;i<=n;i++) { long add=0; end+=log10(a); for(int i=begin;i<=int(end);i++) { add+=a*pa[i]; pa[i]=add%10; add/=10; } } } void display(int *pa,int size,int n) { if(n*D>size) { cout<<'.'; for(int i=0;i<n*D-size;i++) cout<<0; for(int i=size-1;i>=O;i--) cout<<pa[i]; cout<<endl; } else { for(int i=0;i<size;i++) if(pa[i]==0) O++; else break; for(int i=size-1;i>=n*D;i--) cout<<pa[i]; cout<<'.'; for(int i=n*D-1;i>=O;i--) cout<<pa[i]; cout<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator