0分求助

P1046 [NOIP2005 普及组] 陶陶摘苹果

Su_AC @ 2024-04-20 17:19:07

可能是低级错误,勿喷谢谢

#include<bits/stdc++.h>
using namespace std;
const int maxn = 11;
int a[maxn];
int main(){
    int n,m,sum;
    for(int i = 1;i <= 10;i++){
        cin >> a[i];
    }
    cin >> n;
    m = n+30;
    for(int i = 1;i <= 10;i++){
        if(a[i] <= m){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

by Su_AC @ 2024-04-20 17:20:26

在dev-c++上好像都没问题


by Unknown_Jun @ 2024-04-20 17:20:47

第六行要将sum初始值设为0


by Su_AC @ 2024-04-20 17:24:02

谢谢 @Unknown_Jun


by Su_AC @ 2024-04-20 17:25:59

呃,改完后变成了90分

#include<bits/stdc++.h>
using namespace std;
const int maxn = 11;
int a[maxn];
int main(){
    int n,m,sum = 0;
    for(int i = 1;i <= 10;i++){
        cin >> a[i];
        a[i]++;
    }
    cin >> n;
    m = n+30;
    for(int i = 1;i <= 10;i++){
        if(a[i] <= m){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

by Su_AC @ 2024-04-20 17:30:40

原地去世


by bulopi @ 2024-04-20 18:08:12

第九行的a[i]++;是不需要的,去掉即可AC,以下是完整代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 11;
int a[maxn];
int main(){
    int n,m,sum = 0;
    for(int i = 1;i <= 10;i++){
        cin >> a[i];
    }
    cin >> n;
    m = n+30;
    for(int i = 1;i <= 10;i++){
        if(a[i] <= m){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

(球关)


by Xingyi_2014 @ 2024-07-28 11:45:41

#include <bits/stdc++.h>
using namespace std;
int height,a[10],x,sum;
int main(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    cin>>height;
    x=height+30;
    for(int i=0;i<10;i++){
        if(a[i]<=x) sum++;  
    }
    cout<<sum;
    return 0;
}

by Xingyi_2014 @ 2024-07-28 11:46:10

求关注


|