1144 The Missing Number (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:

  1. 10
  2. 5 -25 9 6 1 3 4 2 5 17

Sample Output:

  1. 7
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. int a[];
  6.  
  7. int main(){
  8. int n;
  9. cin >>n;
  10. for(int i=;i < n;i++){
  11. cin >> a[i];
  12. }
  13.  
  14. sort(a,a+n);
  15.  
  16. int cnt = ;
  17.  
  18. for(int i=;i < n;i++){
  19. if(a[i] > ){
  20. if(a[i]>cnt){
  21. cout << cnt;
  22. return ;
  23. }
  24. else if(a[i] == cnt){
  25. cnt++;
  26. }
  27. }
  28. }
  29. cout << cnt;
  30.  
  31. return ;
  32. }

做水题的感觉也太棒了8

  1.  

PAT 1144 The Missing Number的更多相关文章

  1. PAT 1144 The Missing Number[简单]

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  2. [PAT] 1144 The Missing Number(20 分)

    1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...

  3. PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)

    1144 The Missing Number (20 分)   Given N integers, you are supposed to find the smallest positive in ...

  4. PAT(A) 1144 The Missing Number(C)统计

    题目链接:1144 The Missing Number (20 point(s)) Description Given N integers, you are supposed to find th ...

  5. PAT 甲级 1144 The Missing Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 Given N integers, you ...

  6. 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 ...

  7. 1144 The Missing Number (20 分)

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

  8. 1144. The Missing Number (20)

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

  9. 1144 The Missing Number

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

随机推荐

  1. class多态

    多态代码实现: class Animal(object): def __init__(self, name): # Constructor of the class self.name = name ...

  2. python zip()函数

    描述 zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表. 如果各个迭代器的元素个数不一致,则返回列表长度与最短的对象相同,利用 * 号操作符 ...

  3. Oracle GoldenGate 18.1发布

    软件下载地址:https://www.oracle.com/technetwork/middleware/goldengate/downloads/index.html 文档下载地址: https:/ ...

  4. 连阿里都在用它处理亿万级数据统计,论其对Java程序员的重要性!

    一.了解淘宝Kafka架构 在ActiveMQ.RabbitMQ.RocketMQ.Kafka消息中间件之间,我们为什么要选择Kafka?下面详细介绍一下,2012年9月份我在支付宝做余额宝研发,20 ...

  5. spark报错解决

    19/03/04 18:18:42 ERROR Shell: Failed to locate the winutils binary in the hadoop binary path java.i ...

  6. FairyGUI TextField

    记录一个在使用FairyGUI的TextField时遇到的坑. TextField有一个文本模板功能,可以实现类似占位符的功能,如:{ number = 0 },然后我们可以在脚本中修改number的 ...

  7. Flutter 输入控件TextField设置内容并保持光标(cursor)在末尾

    TextField( controller: TextEditingController.fromValue(TextEditingValue( // 设置内容 text: inputText, // ...

  8. python操作字符串类型json的注意点

    python操作json的方法有json.dumps——将json对象(字典)转换为字符串对象json.loads——将字符串对象转换为json对象(字典)如果定义json对象jsonstring1= ...

  9. linux查看服务器并发连接数

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(key in S) print key,"\t",S[key]}'

  10. MySql 查询表结构信息

    select Column_name as 列名,is_nullable as 是否可为空,data_type as 数据类型,column_default as 默认值,case when colu ...