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 ...
随机推荐
- 莫名奇妙虚拟机 ip addr 不显示 ip 地址,连不上网络
CentOS7 Failed to start LSB: Bring up/down networking. 说是mac地址不对.其实,本人并没有配置mac,按理说用的默认的.之前一直是可以正常工作的 ...
- DataGridView上下键事件获取到的是上次停留行的内容
DataGridView上下键事件 在DataGridView中,通过上下键将选中行的内容返回, 问题: 通过上边的方法总是获取到上次停留行的内容,不是当前选中行的内容. winform的项目,使用C ...
- Saiku资源帖
一.精选 1.李秋 随笔分类 - pentaho 二.概述 1.Saiku + Kylin 多维分析平台探索 三.Saiku+Kylin 1.使用Saiku+Kylin构建多维分析OLAP平台 2.使 ...
- redis使用总结(一)(redis客户端使用)
NoSQL 摘自百度百科 NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得 ...
- vue-cli webpack浅析
一直对脚手架的webpack配置很感兴趣. 长话短说,先从npm start开始. 打开package.json 找到scripts 可以看到start 运行的是dev, dev 又是从 build/ ...
- LightGBM算法(转载)
原文:https://blog.csdn.net/niaolianjiulin/article/details/76584785 前者的含义是轻量级,GBM:梯度上升机. 相较于xgboost: 更快 ...
- netperf
官网 下载 装包 yum -y install make automake libtool pkgconfig libaio-devel 编译安装 ./autogen.sh ./configure m ...
- 【题解】Luogu P4867 Gty的二逼妹子序列
原题传送门 同Luogu P4396 [AHOI2013]作业 询问多了10倍,但还能跑过(smog #include <bits/stdc++.h> #define N 100005 # ...
- 单元测试系列之九:Sonar 常用代码规则整理(一)
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 摘要:公司部署了一套sonar,经过一段时间运行,发现有一些问题出现频率很高,因此有必要将这些问题进行整理总结和分 ...
- JS(JavaScript)的初了解6(更新中···)
Js数据类型具体分析 基础类型: string number boolean null undefined 引用类型: object ==> json array 等 复习 ...