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> using namespace std; const int maxn=10000; int h[maxn+1]; int m,n; void mul(int h[],int k) { int i; for(i=0;i<=maxn;i++)h[i]=h[i]*k; for(i=0;i<=maxn-1;i++) { h[i+1]+=h[i]/10; h[i]=h[i]%10; } } int main() { int i,j,k,len,p; char s[maxn]; while(scanf("%s%d",s,&n)==2) { m=j=0; len=strlen(s); for(i=0;i<maxn;i++)h[i]=0; h[0]=1; for(i=len-1;i>=0;i--)if(s[i]!='0')break; len=i+1; for(i=0;i<len;i++) { if(s[i]=='.')p=(len-1-i)*n; else m=m*10+s[i]-'0'; } for(i=0;i<n;i++)mul(h,m); i=maxn; j=0; while(i>=0&&h[i]==0)i--; i=max(i,p-1); for(k=i;k>=0;k--) { if(k==p-1)printf(".%d",h[k]); else printf("%d",h[k]); } 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