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

Why WA?

Posted by 00 at 2005-04-01 11:20:16 on Problem 1001
#include<iostream.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
char R[6];
long n,b=0,i,j,k,t,wide;
int *a;
void main()
{
	while(cin>>R>>n)
	{
		for(i=0,j=0;j<6;i++)
		{
			if(R[i]=='.')
			{
				wide=i;
				continue;
			}
			R[j]=R[i];
			j++;
		}
		wide=strlen(R)-wide;
		for(i=0;i<int(strlen(R));i++)
			b+=(R[i]-'0')*long(pow(10,strlen(R)-i-1));
		if(!b)
		{
			cout<<"0"<<endl;
			exit(1);
		}
		t=int(n*log10(b)+1);
		a=new int[t];
		a[0]=1;
		for(i=1;i<t;i++)
			a[i]=0;
		for(i=0;i<n;i++)
		{
			long temp=0;
			for(k=0;k<t;k++)
			{
				temp+=b*a[k];
				a[k]=temp%10;
				temp/=10;
			}
		}
		if(R[0]==48)
		{
			cout<<".";
			for(j=0;j<wide*n-t;j++)
			cout<<"0";
		}
		for(j=0;;j++)
		{
			if(a[j]!=0)
				break;
		}
		for(i=t-1;i>j-1;i--)
		{
			if(i==wide*n-1)
				cout<<".";
			cout<<a[i];
		}
		cout<<endl;
		delete [] a;
	}
}

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