其他分享
首页 > 其他分享> > PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642

PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642

作者:互联网

PAT (Advanced Level) Practice 1144 The Missing Number (20 分) 凌宸1642

题目描述:

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

译:给定 N 个整数,您应该找到不在给定列表中的最小正整数。


Input Specification (输入说明):

Each input file contains one test case. For each case, the first line gives a positive integer N (≤105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.

译:每个输入文件包含一个测试用例。 对于每种情况,第一行给出一个正整数 N (≤105)。 然后在下一行给出 N 个整数,用空格分隔。 所有数字都在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

The Idea:

The Codes:

#include<bits/stdc++.h>
using namespace std ;
const int maxn = 100010 ;
bool exist[maxn] = {false} ; 
int main(){
	int n , t ;
	cin >> n ;
	for(int i = 0 ; i < n ; i ++){
		cin >> t ;
		if(t > 0 && t < maxn) exist[t] = true ; 
	}
	for(int i = 1 ; i < maxn ; i ++){
		if(!exist[i]){
			cout << i << endl ;
			break ;
		}
	}
	return 0 ;
}

标签:PAT,1144,Missing,int,positive,exist,maxn,integer,line
来源: https://www.cnblogs.com/lingchen1642/p/15159557.html