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

1001这个到底怎么错了,请帮我看看,谢谢

Posted by tmsi at 2006-12-27 20:35:31 on Problem 1001
#include <iostream>
#include <vector>
#include <string>

using namespace std;
char szNumber[2048];

inline int max(int a,int b)
{
	return (a>b)?a:b;
}
inline int min(int a,int b)
{
	return (a<b)?a:b;
}
void CAC(const char *A,int nExp)
{
	float fData;
	int i,j;

	sscanf(A,"%f",&fData);


	int iData,iSft=0;
	float fThre=1.0f;
	while(fData-(int)fData>1e-6f*fThre)
	{
		iSft++;
		fData*=10.0f;
		fThre*=10.0f;
	}
	iData=(int)(fData+0.5f);

	iSft*=nExp;

	int iDigit[32];
	int iDataLow=iData%10000;
	int iDataHigh=iData/10000;
	memset(iDigit,0,sizeof iDigit);
	iDigit[0]=iDataLow;
	iDigit[1]=iDataHigh;
	for( i=2;i<=nExp;++i)
	{
		int iDigitTmp[31];
		int iRem=0;
		for( j=0;j<31;++j)
		{
			int iTemp=iDigit[j]*iDataHigh+iRem;
			iRem=iTemp/10000;
			iDigitTmp[j]=iTemp%10000;
		}
		iRem=0;
		int iTemp=(iDigit[0]+iRem)*iDataLow;
		iRem=iTemp/10000;
		iDigit[0]=iTemp%10000;
		for( j=1;j<32;++j)
		{
			int iTemp=iDigit[j]*iDataLow+iRem+iDigitTmp[j-1];
			iRem=iTemp/10000;
			iDigit[j]=iTemp%10000;
		}
	}
	char buff[2048];
	memset(buff,'0',sizeof buff);
	char *sNumber=buff+1600;
	char sNumber2[2048];
	for( i=31;i>=0;--i)
	{
		sprintf(sNumber+(31-i)*4,"%04d",iDigit[i]);
	}
	int iNonZeroHigh=32*4;
	for( i=0;i!=32*4;++i)
	{
		if(sNumber[i]!='0')
			break;
		--iNonZeroHigh;
	}
	int iNonZeroLow=0;
	for( i=32*4-1;i!=-1;--i)
	{
		if(sNumber[i]!='0')
			break;
		++iNonZeroLow;
	}
	if(iNonZeroHigh==0)
		strcpy(szNumber,"0");
	else
	{
		int iLeftShift=max(iNonZeroHigh,iSft);
		strcpy(sNumber2,sNumber+32*4-iLeftShift);
		int iRightShift=min(iNonZeroLow,iSft);
		sNumber2[iLeftShift-iRightShift]=0;
		if(iNonZeroLow>=iSft)
			strcpy(szNumber,sNumber2);
		else
		{
			int iPointPos=iLeftShift-iSft;
			memmove(sNumber2+iPointPos+1,sNumber2+iPointPos,iSft-iRightShift+1);
			sNumber2[iPointPos]='.';
			strcpy(szNumber,sNumber2);
		}
	}
	strcat(szNumber,"\n");

}

int main(int argc, char * argv[])
{
	char s[100];
	int n;
	vector <string> result;

	while(scanf("%s%d",s,&n)==2)
	{
		CAC(s,n);
		result.push_back(szNumber);
	}
	for(int i=0;i<result.size();++i)
	{
		cout<<result[i];
	}
	cout.flush();
	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