zxhiding @ 2022-10-13 11:57:31
#include<stdio.h>
int a[1001],b[101],c[101];
int main(){
int l,m,n=0;
scanf("%d %d",&l,&m);
for(int i=0;i<m;i++){
scanf("%d %d",&b[i],&c[i]);
for(int k=b[i];k<=c[i];k++){
a[k]=1;}
}for(int y=0;y<=l;y++){
if(a[y]=0){
n+=1;}}
printf("%d",n);
return 0;
}
by CreutzWilknare @ 2022-10-13 12:34:35
by zcx20100201 @ 2022-10-13 12:38:59
第11行的if(a[y]=0)应该是if(a[y]==0)。
by liujunjian365581838 @ 2022-10-13 21:28:43
include <iostream>
using namespace std;
int main(){
int i,j,k,m,n,l,sum=0;
int a[10001],q,z; cin>>l>>m;
for(i=0;i<=l;i++)a[i]=0;
for(i=1;i<=m;i++){ cin>>q>>z;
for(j=q;j<=z;j++)if(a[j]==0)a[j]++; }
for(i=0;i<=l;i++)if(a[i]==0)sum++;
cout<<sum;
}