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

1A 怒贴代码

Posted by beijixing266 at 2012-12-01 00:37:29 on Problem 1001
#include<iostream>
using namespace std;
char s[10];
int n;
int h;
int dotpos;
int r[155];//the result

void multi(int r[],int a)
{
	for(int i=0;i<=h;i++)
	{
		r[i]*=a;
	}
	for(int i=0;i<h;i++)
	{
		if(r[i]>9)
		{
			r[i+1]+=r[i]/10;
		}
		r[i]%=10;
	}
	int temp=r[h];
	while(temp)
	{
		r[h++]=temp%10;
		temp/=10;
	}
	h--;
}

int main()
{
	while(cin>>s>>n)
	{
		int num=0;
		h=0;
		for(int i=0;i<6;i++)
		{
			if(s[i]=='.')
			{
				dotpos=(5-i)*n-1;
			}
			else
			{
				num=num*10+s[i]-'0';
			}
		}	
		if(num==0)
		{
			cout<<0<<endl;
			continue;
		}
		memset(r,0,sizeof(r));
		r[0]=1;
		for(int i=0;i<n;i++)
			multi(r,num);
		
		int trail;
		for(int i=0;i<=h;i++)
			if(r[i])
			{
				trail=i;
				break;
			}
		if(dotpos>h)
			h=dotpos;
		int i;
		for(i=h;i>dotpos;i--)
			cout<<r[i];
		if(dotpos>trail)
			cout<<".";
		for(;i>=trail;i--)
			cout<<r[i];
		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