Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个比较短的代码

Posted by tcet030840zxp at 2012-04-16 00:02:44 on Problem 1001
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator