Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
5922 | 邓小龙 | 小明养猪的故事 | C++ | Accepted | 0 MS | 268 KB | 625 | 2024-12-21 10:09:13 |
#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ int T; cin>>T; for(int i=1;i<=T;i++){ int n; cin>>n; int a=1,b=2,c;//c是当天,b是前一天,a是前两天 for(int j=3;j<=n;j++){ c=a+b; a=b; b=c; } if(n==2) cout<<b<<endl; if(n==1) cout<<a<<endl; if(n>=3) cout<<c<<endl; } return 0; }