Missing number(5166)

Missing number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 613    Accepted Submission(s): 345


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. (T10)
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.(1n1,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<iostream>  
#include<string.h>  
#include<stdio.h>  
using namespace std;  
#define N 1005  
int hash[N];  
int main()  
{  
    int t,i,k,x,n;  
    scanf("%d",&t);  
    while(t--)  
    {  
        memset(hash,0,sizeof(hash));  
        scanf("%d",&n);  
        for(i=0;i<n;i++)  
        {  
            scanf("%d",&x);  
            hash[x]=1;  
        }  
        k=0;  
        int ans[2];  
        for(i=1;i<=n+2;i++)  
        {  
            if(!hash[i])      
                ans[k++]=i;  
        }  
        printf("%d %d\n",ans[0],ans[1]);  
    }  

    return 0;  
}  

//0,1的标记。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值