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;
}