PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642
2021/8/19 6:08:55
本文主要是介绍PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642
题目描述:
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
译:给定 N 个整数,您应该找到不在给定列表中的最小正整数。
Input Specification (输入说明):
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.
译:每个输入文件包含一个测试用例。 对于每种情况,第一行给出一个正整数 N (≤105)。 然后在下一行给出 N 个整数,用空格分隔。 所有数字都在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
The Idea:
- 对输入的正数进行标记,标记其存在。
- 依次遍历,第一个没被标记的正数就是答案。
The Codes:
#include<bits/stdc++.h> using namespace std ; const int maxn = 100010 ; bool exist[maxn] = {false} ; int main(){ int n , t ; cin >> n ; for(int i = 0 ; i < n ; i ++){ cin >> t ; if(t > 0 && t < maxn) exist[t] = true ; } for(int i = 1 ; i < maxn ; i ++){ if(!exist[i]){ cout << i << endl ; break ; } } return 0 ; }
这篇关于PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-16优化批处理流程:自定义BatchProcessorUtils的设计与应用
- 2024-09-15laravel collect游标批量插入的方法示例-icode9专业技术文章分享
- 2024-09-15怎么修改laravel的中间件 把获取IP改成X-Real-IP-icode9专业技术文章分享
- 2024-09-15laravel默认分页返回样式是什么-icode9专业技术文章分享
- 2024-09-15服务类中 怎么调用模型基类的函数-icode9专业技术文章分享
- 2024-09-15依赖注入比静态方法有什么好处-icode9专业技术文章分享
- 2024-09-15不使用静态方法控制器调用服务类有什么方法-icode9专业技术文章分享
- 2024-09-15laravel 验证器限制5个汉字以内实现方式-icode9专业技术文章分享
- 2024-09-14从基础到实战:解读CNN资料,轻松掌握卷积神经网络入门知识
- 2024-09-14PingCAP 荣登 2024 Cloud 100 China 第七名