为啥不能编译

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

zengyanx @ 2024-11-21 13:36:26


#include <iostream>
using namespace std;
void main()
{
    int num = 0;
    int a[10];
    for (int i = 0; i < 10; i++)
    {
        cin >> a[i];
    } cout << endl;
    int x;
    cin >> x;
    for (int j = 0; j < 10; j++)
    {
        if (x >= a[j])
            num++;
    }
    cout << endl << num;
}

by Terrible @ 2024-11-21 13:50:41

@zengyanx

标准上从来都写着 main 函数的返回值类型是 intvoid main() 在洛谷环境上是绝对不允许出现的。


by zengyanx @ 2024-11-21 15:18:25

谢谢啦,但还是不能通过 为啥啊@Terrible


by Civilight_Eterna @ 2024-11-21 19:18:13

@zengyanx 你中途换行干什么?????????


by Lanhening @ 2024-11-21 19:31:15


#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
long long n,a[15],sum=0;
int main(){
    for(int i=1;i<=10;i++){
        cin>>a[i];
    }cin>>n;
    for(long long i=1;i<=10;i++){
        if(n+30>=a[i]){
            sum++;
        }
    } cout<<sum;
    return 0;
}

by zengyanx @ 2024-11-21 21:02:27

@Civilight_Eterna为啥不行啊


by zengyanx @ 2024-11-23 13:21:39

@Lanhening

#include <iostream>
using namespace std;
int main()
{
    int num = 0;
    int a[10];
    for (int i = 0; i < 10; i++)
    {
        cin >> a[i];
    } cout << endl;
    int x;
    cin >> x;
    for (int j = 0; j < 10; j++)
    {
        if (x+30 >= a[j])
            num++;
    }
    cout << endl << num;
return 0;
}

谢谢啦,但是为啥我这个不行啊


by SbsbsB_ @ 2024-11-24 13:12:12

@zengyanx 先把第十行的换行( endl )删掉,再把第十八行的换行删掉


by litianyuan0 @ 2024-12-16 18:21:47

#include<iostream>
using namespace std;
int main(){
    long long a,b,c,d,e,f,g,h,i,j,k,cnt=0;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k;
    k=k+30;
    if(k>=a){
        cnt++;
    }
    if(k>=b){
        cnt++;
    }
    if(k>=c){
        cnt++;
    }
    if(k>=d){
        cnt++;
    }
    if(k>=e){
        cnt++;
    }
    if(k>=f){
        cnt++;
    }
    if(k>=g){
        cnt++;
    }
    if(k>=h){
        cnt++;
    }
    if(k>=i){
        cnt++;
    }
    if(k>=j){
        cnt++;
    }
    cout<<cnt;
    return 0;
}

暴力做法 @zengyanx


by weihaisunyingjie @ 2024-12-16 20:00:48

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

|