题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#include<iostream> using namespace std; int main() { int month[1024]; int index = 0; while( cin>>month[index]) { index ++; } for(int j = 0; j < index; j++) { int num =1; if(month[j] < 1) { cout << 0; return 0; } if(month[j] == 1 || month[j] == 2) { cout << 1; return 0; } int tmp = 1; for(int i = 2; i<month[j]; i++) { int x = num; num += tmp; tmp = x; } cout << num <<endl; } return 0; }