请指点逻辑感觉没问题,暂时先不考虑按题目格式输入输出,数列一直不对
查看原帖
请指点逻辑感觉没问题,暂时先不考虑按题目格式输入输出,数列一直不对
1580346
sorrymaker12138楼主2024/11/29 14:21
#include<iostream>

using namespace std;
int main()
{
    int a,b,c,num;
    a=1;
    b=1;
    c=0;
    num=0;
    cin>>num;
for(int j=0;j<num;j++){
    int d=0;
    cin>>d;
    if(d==1)
	{cout<<a<<endl;}
	else if(d==2)
	{cout<<b<<endl;}
	else
	{
    for(int i=2;i<d;i++){
        c=a+b;
        a=b;
        b=c;
    }
    cout<<b<<endl;
}
}
    return 0;
}
2024/11/29 14:21
加载中...