2015 HUAS Provincial Select Contest #2~A

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 \leq 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 \leq n \leq 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
解题思路:这个题要注意的是长度为n的排列就是从1~n这连续的n个数,而不是任意数;其次,大数组一般是定义在函数外,或者动态申请的,不会在栈中。因为桟的内存比较小,没有主函数外大,定义在内部容易造成系统栈过载的这种错误。
程序代码:
#include<cstdio>
const int maxn=1000;
int a[1000],b[1000];
int main()
{
 int T;
 scanf("%d",&T);
 while(T>=1&&T<=10)
 {
 
  while(T--)
  {
   int i,n,k;
         scanf("%d",&n);
   if(n>=1&&n<=1000)
   {
    k=0; 
    for(i=0;i<n;i++)
                 scanf("%d",&a[i]);
             for(i=0;i<n+2;i++)
     b[i]=i+1;
    for(i=0;i<n;i++)
    {
     for(int j=0;j<n+2;j++)
     {
      if(a[i]==b[j])
      b[j]=0;
     }
    }
   
    for(i=0;i<n+2;i++)
    {
     if(b[i]!=0) 
     {
      k++;
      printf("%d",b[i]);
      if(k==2)  printf("\n");
      else printf(" ");
     }
    }
   }
  }
 }
 return 0;
}
posted @ 2015-07-18 15:19  简约。  阅读(133)  评论(0编辑  收藏  举报