Link:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=564&pid=1001
Missing number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.
Input
There is a number T shows there are 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 has. In following a line , there are n distinct postive integers.( 1≤n≤1,000 )
Output
For each case output two numbers , small number first.
Sample Input
2 3 3 4 5 1 1
Sample Output
1 2 2 3
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int a[1111],t[1111];
int main()
{
int p,n;
scanf("%d",&p);
while(p--)
{
memset(t,0,sizeof(t));
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
t[a[i]]=1;
}
int flag = 1;
for(int i=1;i<=n+2;i++)
{
if(!t[i]&&flag){
printf("%d ",i);
flag=0;
}
else if(!t[i]&&!flag){
printf("%d\n",i);
}
}
}
return 0;
}