哪错了啊??调试时一点问题没有,答案也是对的,提交时一直0分??

jianyuechen 2023-01-11 10:56:32 2023-01-11 11:02:36 36
#include<bits/stdc++.h>
using namespace std;
double a[71];
int main(){
	int n;
	a[1]=1;
	a[2]=2;
	a[3]=4;
	for(int i=4;i<=71;i++){
		a[i]=a[i-1]+a[i-2]+a[i-3];
	}
	while(cin>>n){
		if(n!=0){
			cout<<a[n]<<endl;
		}
	}
    return 0;
}
{{ vote && vote.total.up }}

共 8 条回复

tctm229

#include <bits/stdc++.h> using namespace std; long long n, a[101] = { 1, 2, 4 }; int main() { for (int i = 3; i < 71; i++) { a[i] = a[i - 1] + a[i - 2] + a[i - 3]; } while (cin >> n && n != 0) { cout << a[n - 1] << endl; } return 0; }

root 站长

👍

huruixi

如果n==0,那么就break或者直接return 0

huruixi

没有开long long

huruixi
root 站长

👍

novice 刷题

double精度不够 换个定义类型吧

jianyuechen

换了方式也一直说不对???是哪里出错了啊