poj 3982- 序列-大整数加法

B - 序列
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

数列A满足An = An-1 + An-2 + An-3, n >= 3 

编写程序,给定A0, A1 和 A2, 计算A99

Input

输入包含多行数据 

每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 32767) 
数据以EOF结束

Output

对于输入的每一行输出A99的值

Sample Input

1 1 1

Sample Output

69087442470169316923566147
 
   
#include <stdio.h>
#include <string.h>
#define TT 106

int a[TT], b[TT], c[TT];

void solve(){
	int TIME = 99;
	while (TIME -- ){
		for (int i=0; i<TT; ++i){
			a[i] += b[i] + c[i];
			if (a[i] > 9){ 
				a[i+1] += a[i] / 10;
				a[i] %= 10;
			}
		}
		for (int i=0; i<TT; ++i){
			int tmp = a[i];
			a[i] = b[i];
			b[i] = c[i];
			c[i] = tmp;
		}
	}
	TIME = TT;
	while (!a[TIME--]);
	for (int i=TIME+1; i>=0; --i)
		printf("%d", a[i]);
	printf("\n");
}

void init(int x, int y, int z){
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(c, 0, sizeof(c));
	int i=0;
	while (x > 0){
		a[i++] = x % 10;
		x /= 10;
	}
	i = 0;
	while (y > 0){
		b[i++] = y % 10;
		y /= 10;
	}
	i = 0;
	while (z > 0){
		c[i++] = z % 10;
		z /= 10;
	}
}
int main(){
	int x, y, z;
	while (~scanf("%d%d%d", &x, &y, &z)){
		init(x, y, z);
		solve();
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值