求助编译错误

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

chenxinhao0402 @ 2023-02-01 08:32:16

#include<cstdio>
using namespace std;
int main() 
{
    int l,m,tree[10010]={0},a,b,s=0;
    memset(tree,0,sizeof(tree));
    for (int i=0;i<m;i++)
    {
        scanf("%d%d",&a,&b);
        for(int j=a;j<=b; j++)
            tree[j]=1;
    }
    for(int i=0;i<=1,i++);
        if(tree[i]==0)s++;
    printf("%d",s);
    return 0;
}

by zgy_123 @ 2023-02-01 08:35:48

@chenxinhao0402 for后面有分号


by Misophiliac @ 2023-02-01 08:36:24

@chenxinhao0402

  1. memset需要加cstring头文件

  2. 后面循环改为

    for(int i=0;i<=1;i++)
    if(tree[i]==0)s++;

by chenxinhao0402 @ 2023-02-01 08:43:14

不行啊,全WA了


by hzoi_Shadow @ 2023-02-01 08:44:29

请问lz的l,m输入了吗


by chenxinhao0402 @ 2023-02-01 08:46:37

int后面跟了啊


by Misophiliac @ 2023-02-01 08:49:11

@chenxinhao0402 最后一个循环是到l吧


by chenxinhao0402 @ 2023-02-01 08:49:31

@The_Shadow_Dragon


by hzoi_Shadow @ 2023-02-01 08:50:03

@chenxinhao0402 你只是定义,没有输入


by chenxinhao0402 @ 2023-02-01 08:51:09

for(int i=0;i<=1,i++);
    if(tree[i]==0)s++;
printf("%d",s);
return 0;

这样?


by chenxinhao0402 @ 2023-02-01 08:54:04

#include<cstdio>
#include<cstring>
using namespace std;
int main() 
{
    int l,m,tree[10010]={0},a,b,s=0;
    scanf("%d%d",&l,&m);
    memset(tree,0,sizeof(tree));
    for (int i=0;i<m;i++)
    {
        scanf("%d%d",&a,&b);
        for(int j=a;j<=b; j++)
            tree[j]=1;
    }
    for(int i=0;i<=1;i++)
    if(tree[i]==0)s++;
    printf("%d",s);
    return 0;
}

采纳


| 下一页