1 条题解

  • 0
    @ 2021-6-14 23:29:50

    C :

    #include <stdio.h>
    int main()
    {int a[10001]={0},b,c,i,j,h=0;
    scanf("%d%d",&b,&c);
    while(c--)
    {scanf("%d%d",&i,&j);
    while(i<=j)
    {
    a[i++]=1;
    };
    };
    while(b>=0)
    {
    if(a[b]==0)
    h++;
    b--;
    };
    printf("%d\n",h);
    return 0;
    }
    

    C++ :

    #include<iostream>
    using namespace std;
    int n,i,ans,all,r,l,j;
    int c[1000001];
    int main()
    {
        cin>>all>>n;
        for(i=1;i<=n;i++)
        {cin>>l>>r;
        for(j=l;j<=r;j++)c[j]=1;
        }
        for(j=0;j<=all;j++)
        if(c[j]==0)ans++;
        cout<<ans;
        return 0;
    }
    

    Pascal :

    var m,n,x,y,i,j,ans:longint;a:array[0..10000]of longint; 
    begin
      readln(m,n); 
      for i:=1 to n do
        begin
          read(x,y); 
          for j:=x to y do a[j]:=1; 
        end; 
      for i:=0 to m do if a[i]=0 then ans:=ans+1; 
      writeln(ans); 
    end. 
    
    • 1

    信息

    ID
    239
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者