POJ3982:序列
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
[cpp]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void add(char a[],char b[],char back[])
{
int i,j,k,up,x,y,z,l;
char *c;
if(strlen(a) > strlen(b))
l = strlen(a)+2;
else
l = strlen(b)+2;
c = (char*)malloc(l*sizeof(char));
i = strlen(a)-1;
j = strlen(b)-1;
k = 0;
up = 0;
while(j>=0 || i>=0)
{
if(i<0) x = '0';
else
x = a[i];
if(j<0) y = '0';
else
y = b[j];
z = x-'0'+y-'0';
if(up)
z++;
if(z>9)
{
up = 1;
z%=10;
}
else
up = 0;
c[k++] = z+'0';
i--;
j--;
}
if(up)
c[k++] = '1';
i = 0;
c[k] = '\0';
for(k-=1; k>=0; k--)
back[i++] = c[k];
back[i] = '\0';
}
int main()
{
char a[1000],b[1000],c[1000],sum[1000];
int m,i;
while(~scanf("%s%s%s",a,b,c))
{
add(a,b,sum);
add(c,sum,sum);
int n = 5;
for(i = 1; i<=24; i++)
{
add(b,c,a);
add(sum,a,a);
add(c,sum,b);
add(b,a,b);
add(sum,a,c);
add(b,c,c);
add(a,b,sum);
add(c,sum,sum);
}
printf("%s\n",sum);
}
return 0;
}
补充:软件开发 , C++ ,