HDU 5166(缺失数查找输出)

HDU 5166

Time Limit:1000MS  Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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. (0<=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

 题解:找出一个数列中缺的两个数(这两个数要为最小的两个数)。

  注意:利用bool函数把数组中所有数全部返回0

 

#include<stdio.h>
  int main()
  {
      int T,i;
     scanf("%d",&T);
     while(T--)
      {
          int count,t=0,j[2];;
          scanf("%d",&count);
         bool flag[1005]={  false  };
        for( i=1;i<=count;i++)
         {
             int tem;
             scanf("%d",&tem);
             flag[tem]=true;//每输入一个数s,便给第s个赋值为1
         }
         
         
         for(i=1;i<=count+2;i++)
         {
             if(flag[i]==0)//如果有为0的出现,则为缺失的数
             {
                 j[t++]=i;    
             }
        }
         printf("%d %d
",j[0],j[1]);
         
     }
     return 0;
 }

多多交流~ 

原文地址:https://www.cnblogs.com/hfc-xx/p/4654733.html