求解

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

lzy003 @ 2024-07-28 21:37:56


by cjhhh @ 2024-07-29 09:34:05

@liziyu27 代码呢?


by skyqiu @ 2024-07-29 20:54:17

@liziyu27
#include<bits/stdc++.h>
using namespace std;
int main(){
    int l[10005]={},m,roadlong,ans=0;
    cin>>roadlong>>m;
    for(int i=1;i<=m;i++){
        int begin,end;
        cin>>begin>>end;
        for(;begin<=end;begin++){
            l[begin]=1;
        }
    }
    for(int i=0;i<=roadlong;i++){
        if(l[i]==0){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

代码给了

AC

by percypercy @ 2024-08-02 14:42:32

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

by LEZ2012 @ 2024-08-09 20:08:54


#include<cstdio>
using namespace std;
int a[11],n,s=0;
int main(){
    for(int i=1;i<=10;i++)
    scanf("%d",&a[i]);
    scanf("%d",&n);
    for(int i=1;i<=10;i++)
    if(n+30>=a[i])
    s++; 
    printf("%d",s);
}

by LEZ2012 @ 2024-08-09 20:09:16

互关吗


by tyc20140404 @ 2024-08-16 18:05:11

发一下代码?

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

|