离谱RE
查看原帖
离谱RE
1070628
nyk1315楼主2024/10/5 20:10
#include<bits/stdc++.h>
using namespace std;
int n,k,k2,a[10001],c[1000001],s;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(c[a[i]]!=1)
			s++;
		c[a[i]]=1;
	}
	k2=k;
	for(int i=1;i<=k2;i++){
		if(c[i]!=1)
			k2++;
	}
	if(k>s)
		cout<<"NO RESULT";
	else
		cout<<k2;
	return 0;
} 

为啥上面#4#9RE 但下面代码AC

#include<bits/stdc++.h>
using namespace std;
int n,k,a[10001],c[1000001],s;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(c[a[i]]!=1)
			s++;
		c[a[i]]=1;
	}
	if (k>s){
		cout<<"NO RESULT";
		return 0;
	}
	for(int i=1;i<=k;i++){
		if(c[i]!=1)
			k++;
	}
	cout<<k;
	return 0;
} 

难道一定要提前判断可下面我又没对‘k’做处理

2024/10/5 20:10
加载中...