Missing number in array
Given an array of size n-1 and given that there are numbers from 1 to n with one missing, the missing number is to be found.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N.
The second line of each test case contains N-1 input C[i],numbers in array.
Output:
Print the missing number in array.
Constraints:
1 ≤ T ≤ 200
1 ≤ N ≤ 1000
1 ≤ C[i] ≤ 1000
Example:
Input
2
5
1 2 3 5
10
1 2 3 4 5 6 7 8 10
Output
4
9
#include <iostream> #include <algorithm> using namespace std; int main() { int T; cin>>T; while(T--) { int N,i; cin>>N; int *C=new int[N-1]; for(i=0;i<(N-1);i++) cin>>C[i]; sort(C,C+N-1); for(i=0;i<N-1;i++) { if(C[i]!=i+1) { cout<<i+1<<endl; break; } } if(N==1) cout<<"1"<<endl; if(i == N-1) cout<<i+1<<endl; } return 0; }
Missing number in array的更多相关文章
- LeetCode Array Easy 268. Missing Number
Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...
- [Array]268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode] Missing Number 丢失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- Leetcode-268 Missing Number
#268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...
- 【LeetCode】268. Missing Number
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- Java [Leetcode 268]Missing Number
题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...
- Missing Number, First Missing Positive
268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find th ...
- [LintCode] Find the Missing Number 寻找丢失的数字
Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array. Example G ...
- [LeetCode] 268. Missing Number ☆(丢失的数字)
转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...
随机推荐
- params SqlParameter[] commandParameters(转)
C#代码 ExecuteReader(string connectionString, CommandType commandType, string commandText, params Sql ...
- Centos 安装boost库
1.在http://www.boost.org/下载boost安装包boost_1_65_1.tar.gz 2.在Centos上解压tar -zxvf boost_1_65_1.tar.gz后,cd ...
- java.util.HashMap和java.util.HashTable (JDK1.8)
一.java.util.HashMap 1.1 java.util.HashMap 综述 java.util.HashMap继承结构如下图 HashMap是非线程安全的,key和value都支持nul ...
- sublime3配置php环境
最后的演示效果: 1. 按照sublime3开始前的准备工作 Ctrl+Shift+P,再输入install ,最后再输入想要安装的软件 (输入install会有几十秒的延迟,请不要重复操作) 配置p ...
- ASE加密
密码学中的高级加密标准(Advanced Encryption Standard,AES),又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.
- lua 限流
前言 每逢大促必压测,每逢大促必限流,这估计是电商人的常态.每次大促期间,业务流量是平时的几倍十几倍,大促期间大部分业务都会集中在购物车结算,必须限流,才能保证系统不宕机. 限流算法 限流算法一般有三 ...
- Sagit.Framework For IOS 开发框架入门开发教程1:框架下载与环境配置
背景: 前天开源了框架:开源:Sagit.Framework For IOS 开发框架 所以注定要追补一套开发教程了,所以尽量抽空了!!! 步骤 1:下载框架源码 GitHub:https://git ...
- 多线程编程学习笔记——async和await(二)
接上文 多线程编程学习笔记——async和await(一) 三. 对连续的异步任务使用await操作符 本示例学习如何阅读有多个await方法方法时,程序的实际流程是怎么样的,理解await的异步 ...
- Python Django CMDB项目实战之-2创建APP、建模(models.py)、数据库同步、高级URL、前端页面展示数据库中数据
基于之前的项目代码来编写 Python Django CMDB项目实战之-1如何开启一个Django-并设置base页index页文章页面 现在我们修改一个文章列表是从数据库中获取数据, 下面我们就需 ...
- lucene6+HanLP中文分词
1.前言 前一阵把博客换了个模版,模版提供了一个搜索按钮,这让我想起一直以来都想折腾的全文搜索技术,于是就用lucene6.2.1加上HanLP的分词插件做了这么一个模块CSearch.效果看这里:h ...