PAT 1144 The Missing Number
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;
typedef long long ll; int a[]; int main(){
int n;
cin >>n;
for(int i=;i < n;i++){
cin >> a[i];
} sort(a,a+n); int cnt = ; for(int i=;i < n;i++){
if(a[i] > ){
if(a[i]>cnt){
cout << cnt;
return ;
}
else if(a[i] == cnt){
cnt++;
}
}
}
cout << cnt; return ;
}
做水题的感觉也太棒了8
PAT 1144 The Missing Number的更多相关文章
- 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 甲级 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 Given N integers, you ...
- PAT A1144 The Missing Number (20 分)——set
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- 1144 The Missing Number (20 分)
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- 1144. The Missing Number (20)
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- 1144 The Missing Number
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
随机推荐
- cookie,localStorage和sessionStorage的区别
cookie已经很久没有用过了,一直觉得session Storage和local Storage更加好用一些.
- 2017-2018-2 20155228 《网络对抗技术》 实验一:PC平台逆向破解
2017-2018-2 20155228 <网络对抗技术> 实验一:PC平台逆向破解 实验内容 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用 ...
- 服务器被疑似挖矿程序植入,发现以及解决过程(建议所有使用sonatype/nexus3的用户清查一下)
此次服务器被植入挖矿程序发现起来较为巧合,首先是上周三开始,我通过sonatype/nexus3搭建的仓库间歇性崩溃,但是每次重新start一下也能直接使用所以没有彻底清查,去docker logs里 ...
- 前端使用node.js的http-server开启一个本地服务器
前端使用node.js的http-server开启一个本地服务器 在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在http或https的链接时 ...
- nginx 环境不支持thinkPHP
在linux+Nginx+mysql+PHP 新装的服务器下,不支持重写pathinfo功能 . 需要加入这个代码 让Nginx 支持重写功能 location / { if (!-e $reques ...
- Python-----多线程threading用法
threading模块是Python里面常用的线程模块,多线程处理任务对于提升效率非常重要,先说一下线程和进程的各种区别,如图 概括起来就是 IO密集型(不用CPU) 多线程计算密集型(用CPU) 多 ...
- OGG 18.1 for mysql远程捕获测试
Ogg18.1 remote capture要求mysql为5.7版本,只能从linux远程捕获mysql on windows or linux,且不支持DDL捕获.支持远程mysql为commun ...
- js filter 数组去重
let arr = [1, 2, 3, 10, 4, 5, 1, 3, 5]; let stateNumArr = arr.filter((item, index, array) => { re ...
- 关于IIS的4月26日笔记
常用命令: 31. regedit.exe----注册表 48. msconfig.exe---系统配置实用程序 80. services.msc---本地服务设置 93. regedit.exe- ...
- Java笔试
异常 Throwable是Java错误处理的父类,有两个子类:Error和Exception. Error:无法预期的严重错误,导致JVM虚拟机无法继续执行,几乎无法恢复捕捉的 Exception:可 ...