1144 The Missing Number (20 分)
2024-08-26 03:37:53
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 (≤105). 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
#include<cstdio>
const int maxn = ;
bool arr[maxn] = {false}; int main(){
int n;
scanf("%d",&n);
int num;
for(int i = ; i < n; i++){
scanf("%d",&num);
if(num > && num < maxn) arr[num] = true;
}
for(int i = ; i < maxn; i++){
if(arr[i] == false){
printf("%d",i);
return ;
}
}
return ;
}
最新文章
- 浏览器的兼容模式下的button中文字垂直方向不居中显示
- 移动端js知识总结
- php中CURL实现模拟登录并采集数据
- 【架构】RPC 使用 Haproxy、keepalive作为负载均衡
- RabbitMQ中 exchange、route、queue的关系
- Hello world S.B.S.
- UVa 11137 (完全背包方案数) Ingenuous Cubrency
- 基于AgileEAS.NET企业应用平台实现基于SOA架构的应用整合方案-开篇
- MySQL slave状态之Seconds_Behind_Master
- 在C#中使用属性控件添加属性窗口
- Ubuntu 查找命令
- SICP 习题 (1.37)解题总结
- (HTTPS)-tomcat 实现 https 登录,去掉端口号
- django-xadmin隐藏菜单不显示
- JavaScript中的alert、confirm、prompt
- android自动化必备之SDK
- android stuido搭配git常用命令
- MySQL数据库表损坏后的修复方法
- Haproxy Nginx cluster构建
- PHP冒泡排序-手写