萌新求助,本机wa提交ac

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

_154 @ 2022-08-13 09:04:33

#include<iostream>
using namespace std;
int main()
{
    int apple[11];
    for(int i=1;i<=10;i++)
        cin>>apple[i];
    int h,ans;
    cin>>h;
    h+=30;
    for(int i=1;i<=10;i++)
        if(apple[i]<=h)
            ans++;
    cout<<ans;
    return 0;
}

rt,为什么在洛谷 ide 上样例输出是 5 而在 Dev-C++ 上输出 6?/kel


by Z_301 @ 2022-08-13 09:07:58

ans没设初值,这是 ub 。


by dlydly @ 2022-08-13 09:10:22

int h,ans;

一眼初值,鉴定为__


by Hisaishi_Kanade @ 2022-08-13 09:10:36

没赋初值能过是运气吧


by ttq012 @ 2022-08-13 09:11:17

@_154

#include<iostream>
using namespace std;
int main()
{
    int apple[11];
    for(int i=1;i<=10;i++)
        cin>>apple[i];
    int h,ans=0;
    cin>>h;
    h+=30;
    for(int i=1;i<=10;i++)
        if(apple[i]<=h)
            ans++;
    cout<<ans;
    return 0;
}

by _154 @ 2022-08-13 09:11:22

az,谢谢


by Daben1 @ 2022-08-13 09:11:34

我就说我这怎么运行变成48了


by ttq012 @ 2022-08-13 09:11:43

https://www.luogu.com.cn/record/83569714


by Daben1 @ 2022-08-13 09:12:28

@lxylluvio %%%


by LiaoYF @ 2022-08-13 09:23:58

@Nancy 请问为什么要骂人


by _Nancy_ @ 2022-08-13 09:26:40

@Mr_LiaoYifan 不好意思lxy整的


|