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 lengshu at 2011-09-29 10:28:31 on Problem 3982
include <stdio.h>
#include <memory>

#define  DEF_MAX_LEN  2000
#define  DEF_MAX_TIME 100
#define  DEF_BIT_LEN  9
unsigned int nMax = 1000000000;
unsigned int nArray[3][DEF_MAX_LEN];

void ProcessAdd(int nPoint, int &nLenth)
{
	int nAnother1 = (nPoint + 1) % 3;
	int nAnother2 = (nPoint + 2) % 3;
	int nEnterOne = 0;
	for (int i = 0; i < nLenth; i++)
	{
		nArray[nPoint][i] += nArray[nAnother1][i] + nArray[nAnother2][i] + nEnterOne ;
		nEnterOne = 0;
		if (nArray[nPoint][i] >= nMax)
		{
			nEnterOne += nArray[nPoint][i] / nMax;
			nArray[nPoint][i] %= nMax;
		}
	}
	if (nEnterOne > 0)
	{
		nArray[nPoint][nLenth] = nEnterOne;
		nLenth++;
	}
}
int main(int argc, char* argv[])
{
	memset(nArray, 0, 3 * DEF_MAX_LEN * sizeof(unsigned int));
	while(scanf("%u %u %u", &nArray[0][0], &nArray[1][0], &nArray[2][0]) != EOF)
	{
		int nCount = 3;
		int nPoint = -1;
		int nLength = 1;
		for (; nCount < DEF_MAX_TIME; nCount++)
		{
			nPoint = (nPoint + 1) % 3;
			ProcessAdd(nPoint, nLength);
		}

		printf("%u", nArray[nPoint][nLength - 1]);
		for (int nPos = nLength - 2; nPos >= 0; nPos--)
		{
			unsigned nMark = 1;
			int nLen = 0;
			for (; nLen < DEF_BIT_LEN; nLen++)
			{
				if (nArray[nPoint][nPos] / nMark == 0)
					break;
				nMark *= 10;
			}
			for (int nZero = DEF_BIT_LEN; nZero > nLen; nZero--)
				printf("0");
			printf("%u", nArray[nPoint][nPos]);
		}
		printf("\n");
		memset(nArray, 0, 3 * DEF_MAX_LEN * sizeof(unsigned int));
	}
	return 0;
}
测试数据:
0 0 0
0
1 1 1
69087442470169316923566147
2 2 2
138174884940338633847132294
3 3 3
207262327410507950770698441
4 4 4
276349769880677267694264588
5 6 7
427754062987361451295487810
9 9 9
621786982231523852312095323
111 111 111
7668706114188794178515842317
234 455 566
31169355880763566758453906103
0 1 0
24332675219681431451788241
0 0 1
28992087708416717612934417
1 1 0
40095354761752599310631730

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