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. Python学习——编程语言介绍

    开发语言 高级语言:基于C/汇编等封装的语言,如Python.Java.C#.PHP.Go.ruby.C++……生成字节码让C/汇编去识别 低级语言:直接让计算机底层能识别成机器码的语言(计算机再将机 ...

  2. 使用css来开启硬件加速来提高网站性能

    一.什么是硬件加速 硬件加速就是将浏览器的渲染过程交给GPU处理,而不是使用自带的比较慢的渲染器,这样就可以使得animation与transition更加顺畅.我们可以在浏览器中用css开启硬件加速 ...

  3. OpenCV中Mat的属性

    OpenCV中Mat的属性 最近在做一OpenCV的图像轮廓检验,但当用到霍夫变换时才发现对Mat的属性了解不足.Mat在OpenCV中的地位是及其重要的,因此有必要做一个总结. 大体上来说,Mat是 ...

  4. rem布局注意问题和meta标签

    使用rem前的准备: 如果是移动端,添加name="viewport"的meta标签,其中的属性数值根据实际需求而定: <meta name="viewport&q ...

  5. PHP5.4 连接 SQL SERVER 2008

    PHP链接sqlserver需要先安装驱动,不是先把dll放到ext下面,一重启服务器就完事了. 本地环境: XAMPP 1.8.2 PHP 5.4.31 SQL SERVER 2008 R2 使用的 ...

  6. MSP-EZ430U_02板子测试使用

    1. 实物如下 2. 先上电,显示驱动没安装 3. 找到驱动的位置,不过实际上安装IAR for msp430之后,驱动就自动的识别了.

  7. RDS for MySQL有哪些限制

    原文来自:https://help.aliyun.com/knowledge_detail/41834.html 1.不支持在命令行创建数据库和数据库账号.只支持在RDS管理控制台操作. 2.不支持M ...

  8. 搜索引擎ElasticSearch系列(一): ElasticSearch2.4.4环境搭建

    一:ElasticSearch简介 Elasticsearch is a distributed, RESTful search and analytics engine capable of sol ...

  9. WPF获取窗口句柄

    通过WPF的互操作帮助类WindowInteropHelper,相关连接:https://msdn.microsoft.com/zh-cn/library/system.windows.interop ...

  10. flask ssti python2和python3 注入总结和区别

    总结一下flask ssti的注入语句 代码 import uuid from flask import Flask, request, make_response, session,render_t ...