解题思路:
利用标记数组
注意事项:
明确端点是否包含其中
参考代码:
#include <iostream>
using namespace std;
int main ()
{
int l,m;
cin>>l>>m;
int *p=new int [l+1];
for(int i=0;i<l+1;i++)
*(p+i)=1;
for(int i=0;i<m;i++)
{
int temp1,temp2;
cin>>temp1>>temp2;
for(int j=temp1;j<=temp2;j++)
*(p+j)=0;
}
int count=0;
for(int i=0;i<l+1;i++)
if(*(p+i)) count++;
cout<<count<<endl;
return 0;
}
0.0分
0 人评分
C语言考试练习题_排列 (C语言代码)浏览:1315 |
十->二进制转换 (C语言代码)浏览:1291 |
printf基础练习2 (C语言代码)浏览:644 |
WU-C语言程序设计教程(第三版)课后习题11.12 (C++代码)(想学链表的小伙伴可以看看)浏览:898 |
幸运数 (C++代码)浏览:1258 |
Tom数 (C语言代码)浏览:725 |
蚂蚁感冒 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:463 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:610 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:582 |