PAT甲级——A1144 TheMissingNumber【20】
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
Solution:
水题,没得意思
两种方法,用map存储后查找即可
另一种方法就是排序后从1查找即可
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n, x, res = ;
vector<int>v;
cin >> n;
while (n--)
{
cin >> x;
if (x > )
v.push_back(x);
}
sort(v.begin(), v.end());
for (auto a : v)
if (a == res)
res++;
cout << res;
return ;
}
PAT甲级——A1144 TheMissingNumber【20】的更多相关文章
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT甲级——1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- PAT甲级——1061 Dating (20分)
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...
- PAT甲级——1005.SpellItRight(20分)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- PAT甲级——1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
随机推荐
- Html5 学习笔记 --》html基础 css 基础
HTML5 功能 HTML5特点 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta cha ...
- js记住密码
$(function () { if (getCookie("rmbUser") == "true") { $("#xuanzong") ...
- Java迭代器模式
迭代器模式是Java和.Net编程环境中非常常用的设计模式.此模式用于以顺序方式访问集合对象的元素,而不需要知道其底层表示. 迭代器模式属于行为模式类别. 实现实例 在这个实例中,将创建一个Itera ...
- CentOS中svn的搭建
1:使用yum源进行安装 # rpm -qa subversion //检查是否自带了低版本的svn #yum remove subversion //卸载低版本的svn #Yum install s ...
- Unrecognized SSL message, plaintext connection--SSLSocket 代理服务器连接
虽然java代码 URL.openconnect(proxy);已经实现了https客户端通过代理连接服务器 但个人在使用socket https代理http://www.cnblogs.com/h ...
- 49.求1+2+3+.......+n
题目描述: 求1+2+3+...+n的值,要求不能使用乘除法,还有,if,while,for等关键字. 思路分析: 使用递归的解法,但是递归的终止条件需要使用if关键字不符合要求,所以我们利用 ...
- element UI的使用
npm install --save element-ui main.js里面添加 import ElementUI from 'element-ui' import 'element-ui/lib/ ...
- Dagger2 探索记2——四大基本组件(二)
书接上文,先回顾以下前一章写的内容. 内容大概就是在Activity中用@Inject标记一个注入的类,然后在这个类的构造函数上也打个@Inject标记,然后使用@Component来连接两边,完成对 ...
- 分支结构if 语句举例
- C++中static的作用
tatic关键字有俩作用:(1).控制存储分配:(2).控制一个名字的可见性和连接. 随着C++名字空间的引入,我们有了更好的,更灵活的方法来控制一个大项目的名字增长. 在类的内部使用st ...