一维数组加上bool标记的综合使用
2026-10-11 22:16:00
发布于:贵州
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){//m次报数
int idx;
cin>>idx;
a[idx] = 1;
}
int ok=0;//ok标志位,如果输出过,则改变为1,没有输出过,则保持为0
for(int i=0;i<n;i++){//检查0 ~ n-1是不是都等于1
if(a[i]!=1){//不等于1,说明该位置的数没有报,输出该位置的编号
cout<<i<<" ";
ok=1;
}
}
if(ok==0){//没有被改变过,说明都报数了,输出n
cout<<n;
}
return 0;
}
这里空空如也







有帮助,赞一个