_Amy @ 2024-04-21 13:11:14
#include <bits/stdc++.h>
using namespace std;
int a[11];
int main()
{
int x,_ans = 0;
for(int i = 1;i <= 11;i ++)
{
cin >> a[i];
}
cin >> x;
for(int i = 1;i <= 11;i ++)
{
if(x + 30 >= a[i]) _ans ++;
}
cout << _ans;
return 0;
}
by liyuteng @ 2024-04-21 13:14:41
#include <bits/stdc++.h>
using namespace std;
int a[11];
int main()
{
int x,_ans = 0;
for(int i = 1;i <= 10;i ++)
{
cin >> a[i];
}
cin >> x;
for(int i = 1;i <= 10;i ++)
{
if(x + 30 >= a[i]) _ans ++;
}
cout << _ans;
return 0;
}
只有你个苹果,但是你原来的代码输入了11个
by _Amy @ 2024-04-21 13:33:18
@liyuteng 蟹蟹大佬
by GeorgeCHN @ 2024-04-28 15:12:42
第七行:你的数组是11项,下标是0-10,你十一的话数组越界了,改成0-10! (求关注!)
by GeorgeCHN @ 2024-04-28 15:13:27
错了,是1-10
by yuzhang_chen @ 2024-04-29 20:35:51
#include<iostream>
#include<cmath>
using namespace std;
int a[15];
int main()
{
int b,B,A;
for(int i=1;i<=10;i++)
cin>>a[i];
cin>>b;
B=b+30;
int c=0;
for(int i=1;i<=10;i++)
{
if(a[i]<=B)
c++ ;
}
cout<<c;
return 0;
}