老实了,为啥错

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

yyy15967708980 @ 2024-10-30 14:17:32

#include<iostream>
using namespace std;
int main(){
    int a[10086],b,j;
    for(int i=1;i<=10;i++){
        cin>>a[i];//TODO
    }
    cin>>b; //陶陶的身高
    for(int x=1;x<=10;x++){
        if(a[x]<=b) { 
            j=j+1;
        }
        else{
            if(a[x]<=b+30){
                j=j+1;
            }
            return 0;
        }
    }
    cout<<j;
}

by Tomorrow_YYX @ 2024-10-30 14:22:21

@yyy15967708980 你 return 的位置写错了


by a23GCC @ 2024-11-01 18:09:58

#include <bits/stdc++.h>
using namespace std;
int a[55], n, sum;
int main() {
    for (int i = 1 ; i <= 10 ; i ++)
        scanf("%d", &a[i]);
    scanf("%d", &n);
    n += 30;
    for (int i = 1 ; i <= 10 ; i ++)
        if (a[i] <= n)
            sum ++;
    printf("%d", sum);
    return 0;
}

|