当前位置: 首页 > news >正文

【PTA Advanced】1144 The Missing Number(C++)

目录

题目

Input Specification:

Output Specification:

Sample Input:

Sample Output:

思路

代码


题目

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 (≤105). 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

思路

难度评级:⭐️

408算法题出到过这题

最小未出现的正整数一定在1~n+1之间

代码

#include <iostream>
#include <vector>using namespace std;int main(int argc, char** argv) {int n;cin>>n;vector<int> a(n+1);for(int i=0;i<n;i++) {int x;cin>>x;if(x>=1&&x<=n) a[x]=1;}int i;for(i=1;i<=n;i++) {if(a[i]==0) break;}cout<<i;return 0;
}

http://www.lryc.cn/news/14262.html

相关文章:

  • oracle的sqlnet.ora文件配置传输加密算法
  • RK3568存储性能测试
  • Homekit智能家居一智能灯泡
  • 轻量级 Java 权限认证框架——Sa-Token
  • 算法复习(四、五、六)
  • SORT与DeepSORT简介
  • TCP/IP网络编程——多播与广播
  • K8S DNS解析过程和延迟问题
  • 【JavaScript】js实现深拷贝的方法
  • RK3288 GPIO记录
  • MongoDB介绍及使用教程
  • 51单片机开发环境搭建 - VS Code 从编写到烧录
  • python datetime、字符串和时间戳之间的相互转换12小时制和24小时制时间相互转化
  • 百度百科词条怎么做?百度百科词条创建攻略分享
  • 基于Hive的河北新冠确诊人数分析系统的设计与实现
  • k8s二进制部署
  • Windows出现0xc00d36e5错误怎么办?
  • Idea搭建Spring5.3.x源码阅读环境
  • 2.20jdbc
  • 【代码随想录训练营】【Day19休息】【Day20】第六章|二叉树|654.最大二叉树|617.合并二叉树|700.二叉搜索树中的搜索|98.验证二叉搜索树
  • 华为云计算之容灾技术
  • React系列之Redux
  • 最简单得方法解决TCP分包粘包问题
  • 免费使用通配符域名证书
  • 0基础成功转行Python自动化测试工程师,年薪30W+,经验总结都在这(建议收藏)
  • MyBaits
  • kubeadm的部署、Dashboard UI以及连接私有仓库
  • 刷题记录:牛客NC20325[SDOI2009]HH的项链
  • 【REACT-路由v6】
  • 【离散数学】3. 代数系统