0
点赞
收藏
分享

微信扫一扫

PAT 甲级 1144  The Missing Number


1144 The Missing Number (20 point(s))

Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.

Output Specification:

Print in a line the smallest positive integer that is missing from the input list.

Sample Input:

10
5 -25 9 6 1 3 4 2 5 17

Sample Output:

7

经验总结:

emmm  简单的划水题,不多说啦~

AC代码

#include <cstdio>
const int maxn=100010;
bool flag[maxn]={false};
int main()
{
int n,t;
scanf("%d",&n);
for(int i=0;i<n;++i)
{
scanf("%d",&t);
if(t<maxn&&t>0)
flag[t]=true;
}
for(int i=1;i<maxn;++i)
if(flag[i]==false)
{
printf("%d\n",i);
break;
}
return 0;
}

 

举报

相关推荐

0 条评论