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

为什么错了呢。。sample 无头绪 有数据么。。

Posted by luxury2664 at 2010-11-26 20:14:30 on Problem 3982
#include <stdio.h>
#include <iostream>

using namespace std;

int num[4][88];

int max(int a, int b, int c) 
{
	int max_abc = a;

	if (max_abc > b)
		max_abc = b;
	if (max_abc > c)
		max_abc = c;

	return max_abc;
}

void caculate(int i, int j) 
{
	int l, k;

	l = max(num[j][0], num[(j + 1) % 4][0], num[(j + 2) % 4][0]);

	for (k = l; k >= 0; k--) {
		num[i][k] = 0;
	}

	for (k = 1; k < l + 3; k++){
		num[i][k] += num[j][k] + num[(j + 1) % 4][k] + num[(j + 2) % 4][k];
		while (num[i][k] >= 10) {
			num[i][k] -= 10;
			num[i][k + 1]++;
		}
	}
	l += 3;
	while (num[i][l] == 0 )
		l--;
	num[i][0] = l;
}

int main()
{
	int a, b, c, i;
	while (scanf("%d%d%d", &a, &b, &c) != EOF) {
		if (a == 0 && b == 0 && c == 0) {
			printf("0\n");
			continue;
		}
		for (i = 0; i < 88; i++) {
			num[0][i] = 0;
			num[1][i] = 0;
			num[2][i] = 0;
			num[3][i] = 0;
		}
		
		i = 1;
		while (a > 0) {
			num[0][i++] = a % 10;
			a /= 10;
		}
		num[0][0] = i;
		i = 1;
		while (b > 0) {
			num[1][i++] = b % 10;
			b /= 10;
		}
		num[1][0] = i;
		i = 1;
		while (c > 0) {
			num[2][i++] = c % 10;
			c /= 10;
		}
		num[2][0] = i;
		for (i = 3; i < 100; i++) {
			caculate(i % 4, (i - 3 ) % 4);
		}
		for (i = num[3][0]; i > 0; i--) {
			printf("%d", num[3][i]);
		}
		printf("\n");
	}
	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