PAT 1144

题目 : The Missing Number

分值 : 20
难度 : 水题
思路 : 用一个 map标记是否出现,从1开始往后遍历找到第一个缺少的i
坑点 : 

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <map>
using namespace std;
map <int , bool> db ;
int main()
{
int N ,temp;
cin>> N ;
for(int i = 0 ; i< N ; i++)
{
cin >>temp;
db[temp] =1 ;
}
for(int i = 1 ; i<1000000; i++)
{
if(db[i]==0)
{
cout << i<<endl ;
break ;
}
}
}