1.Link:
http://poj.org/problem?id=3982
2.Content:
序列
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7057 Accepted: 3182 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 1Sample Output
69087442470169316923566147Source
3.Method:
套用大数相加模板
http://www.cnblogs.com/mobileliker/p/3512632.html
4.Code:
#include <iostream> #include <string> using namespace std; ; string sum(string s1,string s2) { if(s1.length()<s2.length()) { string temp=s1; s1=s2; s2=temp; } int i,j; ,j=s2.length()-;i>=;i--,j--) { s1[i]=?s2[j]-)); //注意细节 ) { s1[i]=+'); ]++; '+s1; } } return s1; } int main() { //freopen("D://input.txt","r",stdin); int i; string str0,str1,str2,str3; while(cin >> str0 >> str1 >> str2) { //cout << str0 << endl; //cout << str1 << endl; //cout << str2 << endl; i = Num - ; while(i--) { str3 = sum(str0,str1); str3 = sum(str3,str2); str0 = str1; str1 = str2; str2 = str3; } cout << str3 << endl; } ; }
5.Reference: