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 (≤10​5​​). 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

题意:给出n个数,输出不在给出的数中的最小正整数。
分析:1.用set去接收这些数(排序+去重)
题解:

 #include<cstdlib>
 #include<cstdio>
 #include<set>
 using namespace std;
 int main() {
     int n;
     set<int> s;
     scanf("%d", &n);
     ; i != n; i++) {
         int t;
         scanf("%d", &t);
         s.insert(t);
     }
     int pre = *(s.begin());
     for (set<int>::iterator it = ++s.begin(); it != s.end(); it++) {
          && pre+ > ) {
             printf();
             ;
         }
         pre = *(it);
     }
     //如果遍历到最后一个仍然找不到符合要求的结果,
     //则输出最大的数之后的正整数(最大的数可能为正,或者仍为负)
     ) {
         printf();
     }
     else {
         printf();
     }
     ;
 }

[PAT] 1144 The Missing Number(20 分)的更多相关文章

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

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

  2. PAT 1144 The Missing Number

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

  3. PAT 1144 The Missing Number[简单]

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

  4. 1144. The Missing Number (20)

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

  5. PAT A1019 General Palindromic Number (20 分)

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

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

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

  7. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  8. PAT乙级:1088 三人行 (20分)

    PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...

  9. PAT乙级:1064 朋友数 (20分)

    PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...

随机推荐

  1. BZOJ1492: [NOI2007]货币兑换Cash 【dp + CDQ分治】

    1492: [NOI2007]货币兑换Cash Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 5391  Solved: 2181 [Submit][S ...

  2. BZOJ2006 [NOI2010]超级钢琴 【堆 + RMQ】

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MB Submit: 3446  Solved: 1692 [Submit][Sta ...

  3. 洛谷 P1516 青蛙的约会 解题报告

    P1516 青蛙的约会 题目描述 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件 ...

  4. 被引用的外部JS存在window.onload时,判断当前页面是否已存在window.onload,并进行相应处理

    如果页面a.html引用了b.js,b.js里的方法需要在页面资源加载完成后执行,即在window.onload里执行:这时如果a.html里使用了window.onload方法,b.js就不能重复调 ...

  5. qt4+vs2010 环境搭建

    1.安装开发所需的软件: vs2010(包括VS2010SP1dvd1,Visual_Assist_X_10.9.2062.0_Crack等) QT: qt-win-opensource-4.8.5- ...

  6. HDU3666 差分约束

    THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. IAR ------ 扩展关键字__weak

    __weak作用:允许多个同名函数同时存在,但是最多只有一个没有__weak修饰.如果有non-weak函数(没__weak修饰),则此函数被使用,否则从__weak修饰的函数中选择其中一个. 下图来 ...

  8. 前端PHP入门-001-为什么学习PHP?

    写在前面的话 可能不知道能坚持多久,现在的我喜欢纯文字的描述! 希望能坚持写完,也是对自己的一个鞭策! 总顾及别人,那谁来顾及你! 为什么学习PHP? PHP入门简单,学习入门易入手[呵呵,都这么说, ...

  9. c# 设置和取消文件夹共享及执行Dos命令

    /// <summary> /// 设置文件夹共享 /// </summary> /// <param name="FolderPath">文件 ...

  10. Item 2---遇到构造器具有多个参数时,要考虑用构建器;Builder模式

    问题,面对这种一个构造器具备多个参数的问题,现有的做法是使用重叠构造器的方式,该方式存在的问题: public class NutritionFacts { private final int ser ...