zoukankan      html  css  js  c++  java
  • PAT (Advanced Level) Practice 1144 The Missing Number (20分)

    1.题目

    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

    2.代码

    #include<iostream>
    #include<cstdio>
    #include<unordered_map>
    using namespace std;
    int main()
    {
    	int n, t;
    	unordered_map<int,int>list;
    	scanf("%d", &n);
    	for (int i = 0; i<n; i++)
    	{
    		scanf("%d", &t);
    		if (t>0)
    			list[t]++;
    	}
    	for (int i = 1; i<100002; i++)
    	{
    		if (list[i] == 0)
    		{
    			printf("%d
    ", i);
    			break;
    		}
    	}
    
    
    }
  • 相关阅读:
    2001.3.9 每日总结
    2021.3.5
    2021.3.4每日总结
    2021.3.3每日总结
    每日总结2021.3.2
    2021.1.13
    2021.1.12
    PodPreset
    ingress-nginx安装
    RBAC
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788890.html
Copyright © 2011-2022 走看看