9 degree subject 1122: eat candy, 9 degree subject 1122 candy
-
Description:
-
The famous mother came back from a business trip and brought a box of delicious and exquisite chocolate to her name (N pieces of chocolate in the box, 20> N> 0 ).
Mom told her that she could eat one or two pieces of chocolate each day.
Suppose that the name eats chocolate every day, and ask how many different methods of eating chocolate are there.
For example:
If N = 1, the name will eat it in 1st days. There is one solution in total;
If N = 2, the name can be 1 in 1st days, 1 in 2nd days, or 2 in 1st days. There are two solutions in total;
If N = 3, the name can eat 1 item in 1st days, with 2 items left, or 2 items left in 1st days. Therefore, there are 2 + 1 = 3 naming schemes;
If N = 4, the name can be 1 item in 1st days, with 3 items left, or 2 items in 1st days, with 2 items left. There are 3 + 2 = 5 solutions.
Given N, please write a program to find the number of solutions for eating chocolate by name.
-
Input:
-
The input contains only one row, that is, integer N.
-
Output:
-
Multiple groups of test data may exist. For each group of data,
There is only one output line, that is, the number of plans for the name to eat chocolate.
-
Sample input:
-
4
-
Sample output:
-
5
-
The water question is relatively simple, and the code is directly used:
-
#include <stdio.h>long long computeNumber(int n){ if(n == 1 || n == 2) return n; else { return computeNumber(n - 1) + computeNumber(n - 2); }}int main(){ int n; long long total; while(scanf("%d",&n) != EOF){ total = computeNumber(n); printf("%lld\n",total); } return 0;}