https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160

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 (≤). 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

代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int a[maxn], num[maxn]; int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%d", &a[i]);
if(a[i] < 0 || a[i] > n + 1) continue;
else
num[a[i]] ++;
} for(int i = 1; i <= n; i ++) {
if(num[i] == 0) {
printf("%d\n", i);
return 0;
}
}
printf("%d\n", n + 1);
return 0;
}

  

PAT 甲级 1144 The Missing Number的更多相关文章

  1. PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)

    1144 The Missing Number (20 分)   Given N integers, you are supposed to find the smallest positive in ...

  2. PAT(A) 1144 The Missing Number(C)统计

    题目链接:1144 The Missing Number (20 point(s)) Description Given N integers, you are supposed to find th ...

  3. PAT 1144 The Missing Number

    1144 The Missing Number (20 分)   Given N integers, you are supposed to find the smallest positive in ...

  4. PAT 1144 The Missing Number[简单]

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  5. [PAT] 1144 The Missing Number(20 分)

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  6. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  7. PAT 甲级 1019 General Palindromic Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...

  8. PAT 甲级 1104 sum of Number Segments

    1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...

  9. PAT 甲级 1019 General Palindromic Number(简单题)

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

随机推荐

  1. Leetcode---栈系列刷题(python3实现)----#496 下一个更大元素I

    给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的下一个比其大的值. nums1 中数字 x 的下一个更 ...

  2. TCP/IP协议的数据传输过程详解——IP与以太网的包收发操作

    MTU:一个网络包的最大长度,以太网中一般是1500字节:(含有头部长度,包括IP头部,TCP头部,不包括MAC头部) MSS:除去头部后,一个网络包所能容纳的TCP的数据的最大长度 下图为TCP/I ...

  3. C语言实现选择排序算法

    新人新气象,我又来了,C语言实现选择排序.很基础的东西,原理什么的就不扯了. #include <stdio.h> #include <stdlib.h> #include & ...

  4. 20155301 《Java程序设计》实验五网络编程与安全

    20155301 <Java程序设计>实验五网络编程与安全 实验内容 实验1: 两人一组结对编程:参考http://www.cnblogs.com/rocedu/p/6766748.htm ...

  5. 20155313 2016-2017-2 《Java程序设计》第三周学习总结

    20155313 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 4.1 类与对象 4.1.1 定义类 书本中使用了设计衣服来定义类,一件衣服的设计Cloth ...

  6. SSM框架及例子(转)

    SSM 手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis 博客地址:http://blog.csdn.net/qq598535550/article/detai ...

  7. Potree学习总结

    一.      简介 基于Web端的三维模型展示,这里仅介绍Three.js和Potree. Three.js 是一款基于WebGL的运行在浏览器中的 3D 开源引擎,用它创建各种三维场景.它类似于M ...

  8. [arc063F]Snuke's Coloring 2-[线段树+观察]

    Description 传送门 Solution 我们先不考虑周长,只考虑长和宽. 依题意得答案下限为max(w+1,h+1),并且最后所得一定是个矩形(矩形内部无点). 好的,所以!!!答案一定会经 ...

  9. day1 ORM

    ORM对象关系映射 映射关系: 表名 <-------> 类名 字段 <-------> 属性 表记录 <------->类实例对象 class Customer( ...

  10. win2012r2 关闭中英文悬浮小方框显示

    因为那是微软输入法自带的   2012下关不掉  所以切换成美式键盘就没有了