小白全WA求助,哪里不对求大神指点

P1047 [NOIP2005 普及组] 校门外的树

perfectbit222 @ 2022-09-15 15:37:19


int main()
{
    int a,b,c,d,num=0;
    scanf("%d %d",&a,&b);
    int tree[100000]={0};
    for(int x=0;x<b;x++)
    {
        scanf("%d %d",&c,&d);
        for(int y=c;y<=d;y++)
        {
            tree[c]=1;
            c++;
        }
    }
    for(int z=0;z<=a;z++)
    {
        num=num+tree[z];
    }
    num=(a-num);
    printf("%d",num);
    return 0;
}

by WOERDESUGX @ 2022-09-15 15:57:12

@perfectpk5 最后加个一就好了

还有数组的大小(尽量比所给数据大一点)

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c,d,num=0;
    scanf("%d %d",&a,&b);
    int tree[100001];
    for(int x=0;x<b;x++)
    {
        scanf("%d %d",&c,&d);
        for(int y=c;y<=d;y++)
        {
            tree[c]=1;
            c++;
        }
    }
    for(int z=0;z<=a;z++)
    {
        num=num+tree[z];
    }
    num=(a-num);
    printf("%d",num+1);
    return 0;
}

by WOERDESUGX @ 2022-09-15 16:04:18

@WOERDESUGX 我只是一名蒟蒻(doge)


by perfectbit222 @ 2022-09-15 16:07:17

@WOERDESUGX 提示编译错误/tmp/compiler_udg60f1d/src:1:9: 致命错误:iostream:No such file or directory

1 | #include<iostream>

  |         ^~~~~~~~~~

编译中断。


by WOERDESUGX @ 2022-09-15 16:15:41

@perfectpk5 你是c吗


by WOERDESUGX @ 2022-09-15 16:16:04

@WOERDESUGX 我c++过的


by perfectbit222 @ 2022-09-15 16:30:47

@WOERDESUGX 是C,所以该怎样办(


by WOERDESUGX @ 2022-09-15 16:35:57

@perfectpk5 ok了

#include<stdio.h>
int main()
{
    int a,b,c,d,num=0;
    scanf("%d %d",&a,&b);
    int tree[100001];
    for(int x=0;x<b;x++)
    {
        scanf("%d %d",&c,&d);
        for(int y=c;y<=d;y++)
        {
            tree[c]=1;
            c++;
        }
    }
    for(int z=0;z<=a;z++)
    {
        num=num+tree[z];
    }
    num=(a-num);
    printf("%d",num+1);
    return 0;
}

我真厉害


by perfectbit222 @ 2022-09-15 17:26:28

嗯嗯,谢谢dalao(


|