Coke666zzx @ 2024-11-26 00:16:18
#include <iostream>
using namespace std;
int main()
{
int a[10001]={},l,m,u,v,cnt;
cin>>l>>m;
for(int j=1;j<=m;j++)
{
cin>>u>>v;
for(int s=u;s<=v;s++)
{
a[s]=1;
}
}
for(int c=0;c<=l;c++)
{
if(a[c]==0)
{
cnt++;
}
}
cout<<cnt;
return 0;
}
by kevin110609 @ 2024-11-26 07:39:04
#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;
return 0;
}
看看这个
by kevin110609 @ 2024-11-26 07:39:30
cnt没有赋初值
by Coke666zzx @ 2024-11-26 23:00:24
@kevin110609谢谢