PAT(A) -- 2018春季考试-甲级 1144 The Missing Number (20分)

浅浅的花香味﹌ 2023-02-22 05:30 130阅读 0赞

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:

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

Sample Output:

  1. 7
  2. #include "iostream"
  3. #include "map"
  4. using namespace std;
  5. map<int,int> e;
  6. int main(){
  7. int n,k;
  8. cin>>n;
  9. for (int i=0;i<n;i++)
  10. {
  11. scanf("%d",&k);
  12. e[k]++;
  13. }
  14. int num=1;
  15. while (e[num]>0)num++;
  16. cout<<num<<endl;
  17. return 0;
  18. }

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,130人围观)

还没有评论,来说两句吧...

相关阅读