HJCshifw @ 2022-11-08 09:25:43
#include<stdio.h>
int main(){
int l,m,k,a[100000],count=0,x,y;
scanf("%d",&l);
for(k=0;k<l;k++)
a[k]=1;
scanf("%d\n",&m);
for(k=1;k<m;k++){
scanf("%d %d\n",&x,&y);
for(;x<=y;x++)
a[x]=0;
}
for(k=1;k<l;k++){
if(a[k]==1)
count++;
}
printf("%d",count);
return 0;
}
by sandwich03 @ 2022-11-08 09:46:25
#include <bits/stdc++.h>
using namespace std;
int main()
{
bool a[10005];
int l, m, start, end, s = 0;
cin>>l>>m;
for(int i = 0; i <= l; ++i)
a[i] = true;
for(int i = 0; i < m; ++i)
{
cin>>start>>end;
for(int j = start; j <= end; ++j)
a[j] = false;
}
for(int i = 0; i <= l; ++i)
{
if(a[i])
s++;
}
cout<<s;
return 0;
}
by sandwich03 @ 2022-11-08 09:47:28
@HJCshifw 代码之前的
by Ruiqun2009 @ 2022-11-08 09:50:28
@HJCshifw 你敢在 main()
函数里开数组还不 memset
?
by HJCshifw @ 2022-11-08 10:15:14
@Ruiqun2009 我我我是小白还,不知道啥意思,照猫画虎用的数组
by HJCshifw @ 2022-11-08 10:15:55
@linzhi123 谢谢您不过我才刚开始学c语言,看不太懂c++
by chenyucheng_1 @ 2022-11-08 15:33:51
不仅在main()函数里开数组,还开这么大???