#include<stdio.h>
/*
*初中生一个,想了一天才想出来这道题
*全部是自己的思路,没有看题解
*/
int main(void)
{
long cows = 1;
long add[3] = {0};
long s_cows = 0;
long year;
long now = 0;
long i = 1;
scanf("%d",&year);
add[0] = 1;
year--;
while (year > 0)
{
while (now < year )
{
add[now % 3] = cows;
cows += add[i % 3];
s_cows += add[now % 3];
s_cows -= add[i % 3 ];
i++;
now++;
}
if (year != 0)
printf("%d\n",cows + s_cows);
now = 0;
cows = 1;
add[0] = 1;
add[1] = 0;
add[2] = 0;
s_cows = 0;
i = 1;
scanf("%d",&year);
year--;
}
return 0;
}
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:869 |
A+B for Input-Output Practice (C++代码)浏览:622 |
WU-蓝桥杯算法提高VIP-勾股数 (C++代码)浏览:1665 |
简单的for循环浏览:1468 |
DNA (C语言描述,数据结构)浏览:898 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:612 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:539 |
数对 (C语言代码)浏览:756 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:717 |