求助,输入样例只能输入一个

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

Z1660402068 @ 2024-03-01 22:35:23


int main ()
{
    int l,a[1001]={0},s,sum;
    sum=0;
    scanf("%d%d",&l,&s);
        for(int i=1;i<=s;i++)
        {
            int right,left;
            scanf("%d%d",&left,&right);
            for(i=left;i<=right;i++)
                a[i]+=1;
        }
        for(int i=0;i<=l;i++)
        {
            if(a[i]==0)
            sum++;
        }
     printf("%d",sum);
     return 0;
}

by 杜都督 @ 2024-03-01 23:18:34

  1. a[]开小了,l是e4级别

  2. left ~ right的循环应该新声明一个变量,不应该沿用i

    @Z1660402068


by Z1660402068 @ 2024-03-02 20:17:13

@杜都督 谢谢大佬


|