Miyu original, post Please note: Reprinted from __________ White House
Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1715
Description:
Problem description
The Fibonacci series is defined as follows:
F (1) = F (2) = 1
F (n) = f (n-1) + f (n-2) n> = 3.
Calculate the value of the nth term.
Input
Enter the first behavior as an integer N, And the next n behavior as an integer Pi (1 <= pI <= 1000 ).
Output
The output is n rows, and each row corresponds to F (PI ).
Sample Input
5
1
2
3
4
5
Sample output
1
1
2
3
5
When I look at the question, I will know that it is a big number... directly templates. There is nothing to say.
The Code is as follows:
# Include <iostream>
# Include <string>
Using namespace STD;
String add (string fnum, string snum)
{
If (fnum. Length () <snum. Length () fnum. Swap (snum );
String A = "0 ";
A + = fnum;
For (INT I = 1; I <= fnum. Length (); I ++)
If (I <= snum. Length ())
A [A. Length ()-I] + = snum [snum. Length ()-I]-'0 ';
For (INT I = 1; I <A. Length (); I ++)
{
If (A [A. Length ()-I]> '9 ')
{A [A. Length ()-I]-= 10; A [A. Length ()-i-1] + = 1 ;}
}
While (A [0] = '0') A. Erase (0, 1 );
Return;
}
String f [1001] = {"0", "1", "1 "};
Void setnum ()
{
For (INT I = 3; I! = 1001; ++ I)
{
F [I] = add (F [I-1], F [I-2]);
}
}
Int main ()
{
Int T;
Setnum ();
While (CIN> T)
{
While (t --)
{
Int N;
Cin> N;
Cout <F [N] <Endl;
}
}
Return 0;
}