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

怎么我的程序是RE,各位大牛帮忙看看啊

Posted by Adrianhsm at 2008-10-18 17:18:11 on Problem 1001
#include "stdio.h"
#include "math.h"
#include <string>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
	string czBase;
	int n;
    while( cin>>czBase>>n )
	{
		int iDotPos = czBase.find(".");	
		int iDotRevPos = czBase.length() - iDotPos - 1 ;
		if( iDotPos >= 0 )
		{
			if( czBase.at(0) == '0' )
			{
				czBase.erase( 0, iDotPos+1 );
			}
			else
			{ 
				czBase.erase(  iDotPos,1  );
			}
		}
		
		int iBase = atoi( czBase.c_str() );
		int i = 0;
		int j = 0;
		int interval = 4;
		int iTemp = 10000;
		int carry = 0;
		while( i < n-1 )
		{
			int beginPos = interval;
			string czTemp = "";
			carry = 0;
			while( beginPos < czBase.length() )
			{
				int number = atoi( (czBase.substr( czBase.length()- beginPos, interval)).c_str() );
				beginPos += interval;
				number *= iBase;
				number += carry;
				carry = 0;
				if( number / iTemp != 0 )
				{
					carry =  number / iTemp;
					number -= ( number / iTemp *iTemp  );
				}
				char *temp = new char[1024];
				sprintf( temp, "%d", number );
				string czLocal(temp);
				delete []temp;
				temp = NULL;
				if( czLocal.length() < interval)
				{
					char *pPrefix = new char[ interval - czLocal.length() +1];
					for( int n = 0 ; n < ( interval - czLocal.length());++n )
					{
						pPrefix[n] = '0';
					}
					pPrefix[ n ] = '\0';
					string czPrefix( pPrefix);
					czLocal = czPrefix + czLocal;
					delete []pPrefix;
					pPrefix = NULL;
				}
				string czTempTemp  = czTemp;
				czTemp  = czLocal;
				czTemp += czTempTemp;
				
			}
			{
				int number = atoi( (czBase.substr( 0, czBase.length() - beginPos + interval).c_str()) );
				number *= iBase;
				number += carry;
				carry = 0;
				if( number / iTemp != 0 )
				{
					carry = number / iTemp;
					number -= ( number / iTemp *iTemp  );
				}
				char *temp = new char[1024];
				sprintf( temp, "%d", number );
				string czLocal(temp);
				delete []temp;
				temp = NULL;
				if( czLocal.length() != interval)
				{
					char *pPrefix = new char[ interval - czLocal.length() +1];
					for( int n = 0 ; n < ( interval - czLocal.length());++n )
					{
						pPrefix[n] = '0';
					}
					pPrefix[ n ] = '\0';
					string czPrefix( pPrefix);
					czLocal = czPrefix + czLocal;
					delete []pPrefix;
					pPrefix = NULL;
				}
				string czTempTemp  = czTemp;
				czTemp  = czLocal;
				czTemp += czTempTemp;
			}
			{
				int number  = carry;
				if( number != 0 )
				{
					char *temp = new char[1024];
					sprintf( temp, "%d", number );
					string czLocal(temp);
					delete []temp;
					temp = NULL;
					string czTempTemp  = czTemp;
					czTemp  = czLocal;
					czTemp += czTempTemp;
				}
			}
			czBase = czTemp;
			++i;
		}
		if( iDotPos < 0)
		{
			cout<<czBase<<endl;
		}
		else
		{
			iDotPos = czBase.length() - (iDotRevPos*n);
			if( iDotPos >= 0 )
			{
				string czPrefix = czBase.substr( 0, iDotPos );
				string czPosterior = czBase.substr( iDotPos, czBase.length()-iDotPos);
				czBase = czPrefix;
				czBase = czBase + '.';
				czBase = czBase + czPosterior;				
	
			}
			else
			{
				int iZeroNum = (iDotRevPos*n)-czBase.length();
				iDotPos = 0;
				char *pTemp = new char[ iZeroNum + 1];
				for( int n = 0; n < iZeroNum;++n)
				{
					pTemp[n] = '0';
				}
				pTemp[n] = '\0';
				string pPrefix( pTemp );
				string pPosterior = czBase;
				czBase = '.';
				czBase += pPrefix;
				czBase += pPosterior;

			}		
			int iBegin = iDotPos;
			i = 0;
			while( i < iDotPos )
			{
				if( czBase.at(i) != '0' )
				{
					iBegin  = i;
					break;
				}
				else
				{
					++i;
				}
			}
			int iEnd =  iDotPos-1; 
			i = czBase.length() -1 ;
			while( i > iDotPos )
			{
				if( czBase.at(i) != '0')
				{
					iEnd = i;
					break;
				}
				else
				{
					--i;
				}
			}
			string czFinal = czBase.substr( iBegin, iEnd - iBegin + 1  );
			cout<<czFinal<<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