第一個缺失正數

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
int main(){
	int x;
	char c;
	map<int, bool> mp;
	while(cin>>x){
		c = getchar();
		if(x > 0) mp[x] = true;
		if(c == ';') break;
	}
	int k = 1;
	bool flag = false;
	for(auto it: mp){
		if(it.first != k) {
			cout<<k<<endl;
			flag = true;
			break;
		}
		k++;
	}
	if(!flag) cout<<k<<endl;
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章