码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5166(缺失数查找输出)

时间:2015-07-17 17:49:54      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

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 s;
    scanf("%d",&s);
    flag[s]=true;//每输入一个数s,便给第s个赋值为1
  }

  for(i=1;i<=count+2;i++)
{
    if(flag[i]==0)
  {
    j[t++]=i; //如果有为0的出现,则为缺失的数
  }
}
  printf("%d %d\n",j[0],j[1]);

}
  return 0;
}

多多交流~ 

HDU 5166(缺失数查找输出)

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!