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 ...
随机推荐
- 学习php的步骤是什么?
PHP应该学什么,如何学好PHP (注:原文来自传智播客) 一些共性问题,大致是: 1. 应该怎样学习PHP,学习的顺序是怎样的? 2. PHP学好后,可以做什么事情? 3. 听得懂课,但是一旦自己独 ...
- Java开发中的23种设计模式详解(1)创建型
设计模式(Design Patterns) --可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- mongedb主从
1.mongodb安装 1.将mongodb上传到linux系统 1.解压 tar -zxvf mongodb-linux-x86_64- -C /usr/local/ 这里默认安装到usr/loca ...
- DataX简介
DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.Oracle.SqlServer.Postgre.HDFS.Hive.ADS.HBase.TableStore(O ...
- JS面向对象——构造函数模型
ECMAScript中的构造函数可用来创建特定类型的对象.我们可以创建自定义构造函数,从而定义对象类型的属性和方法,解决工厂模型中对象识别的问题. <!DOCTYPE html> < ...
- 转载关于struts命名空间的一则报警
今天花了点时间把struts2警告事件彻底的测试了一边,终于有点眉目了.希望能给其他人带来一点帮助.文章属于原创.并不需要转载的时候注明出处,而是希望转载的朋友一定要看明白本文内容再转载,因为我你都清 ...
- 【串线篇】MVC与SpringMVC
1.二者区分 MVC: SpringMvc: DispatcherServlet(前端控制器名) 2.springmvc思想 Spring MVC 通过一套 MVC 注解,让 POJO成为处理请求的控 ...
- 【leetcode】1003. Check If Word Is Valid After Substitutions
题目如下: We are given that the string "abc" is valid. From any valid string V, we may split V ...
- 记一次引入less自己坑自己的坑....
loader里该有的loader都有了,但是在npm run dev的时候,就是找不到less文件. 最后,才发现,用了postcss-loader,但是去package.json里查了一下,并没有安 ...
- Java中的小知识。
package jicheng; public class Animal { //定义一个成员变量name. private String name; public String getName() ...