1144 The Missing Number (20 分)

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:

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

Sample Output:

7

先挑软柿子捏一下。其实不用map,排序一下就好了。
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 map<int,int> mp
 5 int main(){
 6     int n, m;
 7     cin >> n;
 8     for(int i = 0; i < n ; i++){
 9         cin >> m;
10         if(m)
11             mp[m] = 1;
12     }
13     for(int i = 1; i <= n+1; i++){
14         if(mp[i] == 0){
15             cout <<i<<endl;
16             return 0;
17         }
18     }
19     return 0;
20 }


原文地址:https://www.cnblogs.com/zllwxm123/p/11276071.html

时间: 2024-10-07 17:37:55

1144 The Missing Number (20 分)的相关文章

PAT Advanced 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 giv

PAT 甲级 1144 The Missing Number

https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 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 eac

PAT 1144 The Missing Number

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

PAT Advanced 1019 General Palindromic Number (20分)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

PAT-进制转换-A1019 General Palindromic Number (20分)

题目描述: 给出两个整数n.b,问十进制整数n在b进制下是否是回文数,若是,则输出Yes:否则,输出No.在此之后输出n在b进制下的表示. 单词:Palindromic Number--回文数:decimal--十进制的. 输入格式: 输入用空格分隔的两个数,第一个数是十进制数n(0<N≤10?9),第二个数是十进制数b( 2≤b≤10?9). 输出格式: 第一行输出Yes或No,第二行输出十进制数n在b进制下的表示,用空格把每个数隔开,末尾不能有多余空格. 样例: 样例一: 输入:27 2 输

PAT 甲级 1104 Sum of Number Segments (20分)(有坑,int *int 可能会溢出)

1104 Sum of Number Segments (20分)   Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0

pat 1092 To Buy or Not to Buy(20 分)

1092 To Buy or Not to Buy(20 分) Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in w

【PAT甲级】1092 To Buy or Not to Buy (20分):哈希

题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805374509498368 1092 To Buy or Not to Buy (20分) Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful

[LintCode] Find the Missing Number II

Giving a string with number from 1 to n in random order, but miss 1 number.Find that number. You can assume n <= 30 Example Given n = 20, str = 19201234567891011121314151618 return 17 Solution 1. DFS Algorithm. 1. set a 1D boolean array: exist[0.....