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 glandon at 2006-07-10 04:27:04 on Problem 1001
#include <iostream>

using namespace std;

/** pow */
int pLen;

/** length of 0 */

int zbLen;
int zfLen;

int DToInt(double);
void Resolve(int,int,int[]);
void Print(int[],int);

int main()
{
	int r,n;
	int rlt[125];
	double R;

	while(cin>>R>>n){
        if(R-0<0.000001)
		{
			cout<<'0'<<'\n';
			return 1;
		}
		memset(rlt,0,sizeof(rlt));
		zbLen=0;
		zfLen=0;

		r=DToInt(R);

		Resolve(r,n,rlt);
		Print(rlt,r);
	}
	return 0;
}

int DToInt(double R)
{
	int r;
	if(R<10){
		r=int((R+0.00001)*10000);
		pLen=4;
	}
	else{
		r=int((R+0.0001)*1000);
		pLen=3;
	}
	return r;
}

void Resolve(int r,int n,int rlt[])
{
	rlt[0]=r%10;
	rlt[1]=r/10%10;
	rlt[2]=r/100%10;
	rlt[3]=r/1000%10;
	rlt[4]=r/10000%10;


	if(rlt[0]==0){
		zbLen++;
		if(rlt[1]==0){
			zbLen++;
			if(rlt[2]==0){
				zbLen++;
				if(pLen==4&&rlt[3]==0){
					zbLen++;
				}
			}
		}
	}

	zbLen*=n;
	zbLen--;

	pLen*=n;
	pLen--;


	if(r<10000){
		zfLen=4*n;
		zfLen--;
	}



	while(n-->1){
		int p=0;

		for(int i=0;i<125;i++){
			rlt[i]=rlt[i]*r+p;
			p=rlt[i]/10;
			rlt[i]=rlt[i]%10;
		}		
	}


}

void Print(int rlt[],int r)
{
	int i;
	if(r<10000){
		i=zfLen;
	} else {
		i=125;
		while(rlt[--i]==0);
	}
	
	while(i>=0){
		if(i==pLen&&zbLen!=pLen)cout<<'.';	
		if(i<=zbLen)break;
		cout<<rlt[i--];
	}
	cout<<endl;
}

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