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的更多相关文章

  1. LeetCode Array Easy 268. Missing Number

    Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...

  2. [Array]268. Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  3. [LeetCode] Missing Number 丢失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  4. Leetcode-268 Missing Number

    #268.  Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...

  5. 【LeetCode】268. Missing Number

    Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...

  6. Java [Leetcode 268]Missing Number

    题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  7. Missing Number, First Missing Positive

    268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find th ...

  8. [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 ...

  9. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

随机推荐

  1. jquery.form.js+jquery.validation.js实现表单校验和提交

      一.jquery引用 主要用到3个js: jquery.js jquery.form.js jquery.validation.js 另外,为了校验结果提示本地化,还需要引入jquery.vali ...

  2. redis字符串结构

    1.字符串SDS struct sdshdr { // buf 已占用长度 int len; // buf 剩余可用长度 int free; // 实际保存字符串数据的地方 // 利用c99(C99 ...

  3. Java之多态

    一.多态 1.含义 一种类型,呈现多种状态.主要关注类多态.方法多态. 2.多态的前提:继承 使用父类引用指向子类对象: Animal a1 = new Cat(): Object a1 = new ...

  4. ubuntu实时显示网速cpu占用和内存占用率

    ubuntu实时显示网速cpu占用和内存占用率 大家在使用ubuntu的时候,有没有想让它实时显示网速,内存占用率,或者cpu占用率呢?现在我就教大家怎么实现,就像下面这样 1. 添加indicato ...

  5. absolute和relative元素 设置百分比宽高的差异

    一般元素在页面所占的空间包括:magin border padding content.以前一直以为子元素设置百分比宽高都是以父元素的content值为基准计算的.但是当子元素的position不同时 ...

  6. ##5.2 Nova计算节点-- openstack pike

    ##5.2 Nova计算节点 openstack pike 安装 目录汇总 http://www.cnblogs.com/elvi/p/7613861.html ##5.2 Nova计算节点 # co ...

  7. mysql故障解决笔记

    错误提示如图 一开始我查询了 [root@web01 mysql]# ls -al /lib/libc* -rwxr-xr-x 1 root root 1909464 Mar 22 01:49 /li ...

  8. 探究PHP底层

    探究PHP底层 1.PHP是什么?   PHP 指的是我们从外面看到的一套完整的系统.这听起来有点糊涂,但其实并不复杂(PHP4 内部结构图).从功能上来分:我们可以分为三部分: 1. 解释器部分(Z ...

  9. spfa_dfs找负环

    luogu #include<iostream> #include<cstdio> #include<cstring> #include<vector> ...

  10. Solr服务在Linux上的搭建

    一.系统环境 注:欢迎大家转载,非商业用途请在醒目位置注明本文链接和作者名dijia478即可,商业用途请联系本人dijia478@163.com. CentOS-6.7-i386-bin-DVD1 ...