CUGBACM15 class BC 28th AHDU 5166 Missing number

Source: Internet
Author: User
Missing Number Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total Submission (s): 1178 Accepted Submission (s): 608


Problem Description There is a permutation without both numbers in it, and now you know what numbers the permutation have. Please find the numbers it lose.
Input There is a number T shows there is t test cases below. (T≤10)
For each test case, the first line contains a integers n, which means the number of numbers the permutation have. In following a line, there is n distinct postive integers. (1≤n≤1,000)
Output for each case output of numbers, small number first.
Sample Input
2 3 3 4 5 1 1
Sample Output
1 2 2 3 Given an arrangement, small yb accidentally lost the arrangement of the two numbers, the input data given is Xiao Ming now have a sequence, the two required to lose the number of columns, and according to the order from small to large output is good; from the given data we can easily infer that the given sequence is 1 to n+2
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[1005];
int main ()
{
    int t;
    CIN >> T;
    while (t--)
    {
        memset (a, 0, sizeof (a));
        int n;
        CIN >> N;
        for (int i = 0; i < n; i++)
        {
            int x;
            CIN >> X;
            a[x]++;
        }
        int ans[2], s = 0;
        for (int i = 1; i < + 5; i++)
        {
            if (a[i] = = 0)
            {
                Ans[s] = i;
                s++;
                if (s = = 2)
                {break
                    ;}}
        }
        cout << ans[0] << "<< ans[1" << Endl;

    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.