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 gaoxiao at 2007-04-08 19:18:29 on Problem 1001
#include<iostream>
#include<memory.h>
using namespace std;

long length(long a)
{
	long i=1;
	while(a/10!=0)
	{
		i++;
		a=a/10;
	}
	return i;
}
long main()
{
	float r;
	long n,t;
	long dot=0,c=0;
	long s[500]={0};
	long i,j,k;

	while(cin>>r>>n)
	{
		for(i=0;i<500;i++)
			s[i]=0;
		if(n==0)
		{
			cout<<"1"<<endl;
			continue;
		}
		if(r*10000<1)
		{
			cout<<"0"<<endl;
			continue;
		}
		
		if(length(long(r))==1)
		{
			dot=4;
			r*=10000;
		}
		else if(length(long(r))==2)
		{
			dot=3;
			r*=1000;
		}
		dot*=n;
		t=long(r);
		for(i=0;t!=0;i++)
		{
			s[i]=t%10;
			t=t/10;
		}
		j=i;
		for(k=1;k<n;k++)
		{
			for(i=0;i<j;i++)
			{
				s[i]=s[i]*r+c;
				c=s[i]/10;
				s[i]=s[i]%10;
			}
			while(c!=0)
			{
				s[i++]=c%10;////
				c=c/10;
			}
			j=i;
		}
		long z=0;
		for(k=0;k<dot;k++)
		{
			if(s[k]==0)
				z++;
			else
				break;
		}
		
		if(i<=dot)
		{
			cout<<".";
			for(i=dot-1;i>=z;i--)
				cout<<s[i];
			cout<<endl;
		}
		else
		{
			for(i=i-1;i>=z;i--)
			{				
				cout<<s[i];
				if(i==dot&&z!=dot)
					cout<<".";
			}
			cout<<endl;
		}
	}
		
	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