题目描述:
有一对兔子,从出生后第3个月起每个月都生一对兔子,一对小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少对?
输入描述:输入int型表示month
输出描述:输出兔子总数int型
输入例子:9
输出例子:34
算法实现:
#include<iostream> #include<string>#include<vector>using namespace std; //************************************************ // * Author: 赵志乾 // * Date: 2017-2-20 // * Declaration: All Rigths Reserved !!! //***********************************************/ int main() { int month; cin>>month; int a1=1,a2=1,a3=2; int ret; switch(month) { case 1: case 2: cout<<1<<endl;break; case 3: cout<<2<<endl;break; default: for(int i=4;i<=month;i++) { ret=a3+a2; a2=a3; a3=ret; } cout<<ret<<endl; } return 0; }
新闻热点
疑难解答
图片精选