Missing number HDU5166

来源:互联网 发布:vb循环语句for next 编辑:程序博客网 时间:2024/04/30 18:20

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  shows there are   test cases below. ( )
For each test case , the first line contains a integers   , which means the number of numbers the permutation has. In following a line , there are  distinct postive integers.( )
 

Output

For each case output two numbers , small number first.
 

Sample Input

233 4 511
 

Sample Output

1 22 3
题意:
给定一个全排列,但是这个全排列中失去了两个数,要你找出这两个数。
思路:用数组把输入的数标记起来,都赋值为1,如果a[i]==1,就证明i没丢失,否则丢失了。
代码:
#include<iostream>#include<algorithm>#include<cstring>int const maxn=1010;int a[maxn];using namespace std;int main(){    int T,n;    cin>>T;        while(T<=10&&T>0&&T--)        {             memset(a,0,sizeof(a));            cin>>n;            for(int i=0;i<n;i++)                {                    int k;                    cin>>k;                    a[k]=1;                }                int flag=1;            for(int i=1;i<=n+2;i++)                   if(!a[i])                   {                       if(flag)                        {cout<<i<<' ';                        flag=0;                   }                   else                    cout<<i;                   }            cout<<endl;        }    return 0;}



0 0
原创粉丝点击