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 ...
随机推荐
- C# 实现http不同方法的请求
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- 错误:软件包:3:docker-ce-18.09.4-3.el7.x86_64 (docker-ce-stable) 需要:container-selinux >= 2.9
命令:yum -y install http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.68-1. ...
- go语言time包的使用
时间类型 time.Time类型表示时间. //时间类型 func timeDemo() { now := time.Now() fmt.Println(now) //2019-04-20 13:52 ...
- python习题一
1.26个字母大小写成对打印,例如:Aa,Bb...... 方法1: for i in range(26): print(chr(65+i)+chr(97+i)) 方法2: for i in rang ...
- vue父组件给子组件传值:属性的形式
1.父组件怎么传值 2.子组件怎么接受值:依赖props 父页面定义的参数接收返回值,到子组件依旧用定义好的参数,在定义参数的类型,然后渲染数据
- vue环境命令
1.下载安装note.js用于VUE开发环境 2.VUE项目开发环境安装依赖,命令行进入项目代码目录下执行如下命令npm install 3.开发环境运行npm run dev 4.打包项目npm r ...
- COMP 321
COMP 321April 24, 2019Questions on this exam may refer to the textbook as well as to the manual page ...
- Java之二分查找算法
算法说明:取中间位置的值与待查字比较.如果比待查字更大,则去列表的前半部分查找,如果比待查字小,则去列表的后半部分查找,直到找到这个待查字,或者返回没有找到这个待查字.其中给定的列表是从大到小排列的有 ...
- webdriver之富文本,Firefox配置加载
chrome驱动下载:http://chromedriver.storage.googleapis.com/index.html 加载浏览器配置,需要用FirefoxProfile(profile_d ...
- 蒙德里安的梦想【状压DP】
求把N*M的棋盘分割成若干个1*2的的长方形,有多少种方案. 例如当N=2,M=4时,共有5种方案.当N=2,M=3时,共有3种方案. 如下图所示: 输入格式 输入包含多组测试用例. 每组测试用例占一 ...