PAT 甲级 1144 The Missing Number
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的更多相关文章
- PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- PAT(A) 1144 The Missing Number(C)统计
题目链接:1144 The Missing Number (20 point(s)) Description Given N integers, you are supposed to find th ...
- PAT 1144 The Missing Number
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- PAT 1144 The Missing Number[简单]
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- [PAT] 1144 The Missing Number(20 分)
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- PAT 甲级 1019 General Palindromic Number(20)(测试点分析)
1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
- PAT 甲级 1104 sum of Number Segments
1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...
- PAT 甲级 1019 General Palindromic Number(简单题)
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
随机推荐
- python2.7入门---2.x与3.x版本区别
Python的3.0版本,常被称为Python 3000,或简称Py3k.相对于Python的早期版本,这是一个较大的升级.为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向 ...
- asp.net页面刷新或者回发后DIV的滚动条位置不变!(转)
源文件:http://www.cnblogs.com/nyth/archive/2011/06/10/2077868.html 当把数据放在div里面,然后给div设置Scroll显示,在页面刷新后或 ...
- BZOJ4034_树上操作_KEY
题目传送门 这道题可以树链剖分+线段树. 其他操作模板,第二个操作只需要将x~x+size[x]-1区间加值即可. code: #include <cstdio> #include < ...
- win2012r2 关闭中英文悬浮小方框显示
因为那是微软输入法自带的 2012下关不掉 所以切换成美式键盘就没有了
- redis sentinel介绍
目录 配置redis主从复制 使用ping命令检查是否启动 主节点查看链接信息 开始部署sentinel 节点 部署sentinel 启动sentinel 演示下故障转移 查看当前sentinel监控 ...
- uvaoj 156Ananagrams(map和vector组合使用)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 准备正式开始学习C++,先发点牢骚
由于职业关系,经常使用AutoCAD之类绘图软件,但这些软件平台的功能,对专业的应用细节来说,并不能全都照顾到,需要一些二次开发,提升一些个性化操作的效率.软件本身也大多提供了开发软件包,AutoCA ...
- Qt 利用XML文档,写一个程序集合 一
接到领导需求安排,说公司未来的硬件设备会越来越多,与每个设备对应的设备检测和设置程序也会增多.导致软甲太多,不好掌控.所以希望做一个完整的软件,但是呢,每个子程序还得独立,应为每个用户购买的设备不是一 ...
- Python接口测试实战3(上)- Python操作数据库
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
- Jmeter接口测试之Get请求
[一] 在测试计划下面添加一个线程组---------->在线程组下面分别添加HTTP请求.响应断言.BeanShellPreProcessor.察看结果树.聚合报告等内容. [二] 将使用的协 ...