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. Gblocks命令行

    使用默认的设置: $ Gblocks proteins.fasta -t=p 必须是 fasta 文件在前,参数在后.若没有参数,则进入交互式界面. Gblocks cds.fasta −t=c −b ...

  2. Verilog HDL 使用规范(一)

    本博文参考:<大规模逻辑设计指导书>,对于写出规范的代码,培养良好的代码风格颇有裨益. wire and register 一个reg变量只能在一个always语句中赋值: 这个说明至关重 ...

  3. 20155318 2016-2017-2 《Java程序设计》第二周学习总结

    20155318 2016-2017-2 <Java程序设计>第二周学习总结 教材学习内容总结 Java编程风格 基本语法与C相似:调用main函数写public static void ...

  4. 20155328 《Java程序设计》 实验二(Java面向对象程序设计) 实验报告

    20155328 <Java程序设计> 实验二(Java面向对象程序设计) 实验报告 单元测试 一.单元测试和TDD 编程时需理清思路,将编程需求等想好,再开始编.此部分可用伪代码实现. ...

  5. 2016-2017-2 20155331 实验二《Java面向对象程序设计》实验报告

    2016-2017-2 20155331 实验二<Java面向对象程序设计>实验报告 实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握U ...

  6. c++ 自定义数据结构运用

    教学内容: 定义结构 定义结构变量 访问结构成员 定义结构数组 实例运用 例:记录学生到校时间(精确到秒) struct mytime { int hour;//时 int min;//分 ...

  7. day6 角点检测

    1.Harris角点检测 # coding=utf-8 import cv2 import numpy as np filename = 'pic5.png' #1.读入一个灰度图像 img = cv ...

  8. 【HNOI2014】世界树

    题面 题解 虚树好题(只是细节太多) 构出虚树后,一定要仔细梳理关键点之间的点是上面属于父亲,下面属于儿子. 然后二分出所有的点的所属就可以了 代码 #include<cstdio> #i ...

  9. springAOP之代理模式

    springAOP指的是在spring中的AOP,什么是AOP,相对于java中的面向对象(oop),在面向对象中一些公共的行为,像日志记录,权限验证等如果都使用面向对象来做,会在每个业务方法中都写上 ...

  10. bilibili携手WeTest,保障视频类应用优质适配体验

    WeTest 导读 中国移动视频用户规模越来越大,各类移动视频APP也百家争鸣, B站作为国内知名的年轻人文化社区,bilibili在推出移动端时,除了坚持自身的独特定位以外,对其APP的质量也十分重 ...