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. (T<=10T≤10)
For each test case , the first line contains a integers  nn , which means the number of numbers the permutation has. In following a line ,
there are  nnN distinct postive integers.(1<=n<=10001≤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
Source
 
代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define FOR_e(i, a, b) for(int i=a; i<=b; i++) using namespace std;
int f[];
int main()
{
int t, dd;
int ma, mi;
scanf("%d", &t);
int i, n;
while(t--)
{
scanf("%d", &n);
memset(f, , sizeof(f));
ma=-; mi=;
for(i=; i<n; i++)
{
scanf("%d", &dd);
f[dd]=;
if(dd>ma) ma=dd;
if(dd<mi) mi=dd;
}
queue<int>q;
while(!q.empty()) q.pop();
for(i=mi; i<=ma; i++)
if(f[i]==)
{
//printf("%d--", i);
q.push(i);
}
if(q.size()>=)
{
dd=q.front(); q.pop(); printf("%d ", dd);
dd=q.front(); q.pop(); printf("%d\n", dd);
}
else if(q.size()==)
{
dd=q.front(); q.pop(); printf("%d ", dd);
if(mi==)
{
printf("%d\n", ma+);
}
else if(mi>)
{
printf("%d\n", mi-);
}
}
else if(q.size()==)
{
if(mi>)
{
printf("%d %d\n", mi-, mi-);
}
else if(mi==)
{
printf("%d %d\n", mi-, ma+);
}
else
{
printf("%d %d\n", ma+, ma+);
}
}
}
return ;
}

Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)的更多相关文章

  1. Missing number - 寻找缺失的那个数字

    需求:给出一个int型数组,包含不重复的数字0, 1, 2, ..., n:找出缺失的数字: 如果输入是[0, 1, 2] 返回 3 输入数组 nums = [0, 1, 2, 4] :应该返回 3 ...

  2. LeetCode 268. Missing Number (缺失的数字)

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  3. 268. Missing Number序列中遗失的数字

    [抄题]: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  4. lintcode 中等题:find the missing number 寻找缺失的数

    题目 寻找缺失的数 给出一个包含 0 .. N 中 N 个数的序列,找出0 .. N 中没有出现在序列中的那个数. 样例 N = 4 且序列为 [0, 1, 3] 时,缺失的数为2. 注意 可以改变序 ...

  5. Valid Number,判断是否为合法数字

    问题描述: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " ...

  6. [LeetCode] Missing Number 丢失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  7. Missing number

    Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...

  8. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  9. Leetcode-268 Missing Number

    #268.  Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...

随机推荐

  1. PropertyPlaceholderConfigurer 基本用法

    目录 一.PropertyPlaceholderConfigurer 的继承体系 二.PropertyPlaceholderConfigurer 的基本概念 三.PropertyPlaceholder ...

  2. MQTT协议介绍

    http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.pdf   MQTT 文档 http://mqtt.org/new/wp-c ...

  3. Windows系统Python包的安装

    本文针对于Python初学者,Python老鸟请绕道. 最近同时尝试在Windows10.MacOS.Ubuntu三个系统上安装Python相关的包,整体比较,Ubuntu最简单,Windows10最 ...

  4. 自签名证书安全性问题研究https(ssl)

    先看下https(ssl)的好处,以及为什么要用: http://imweb.io/topic/565c71673ad940357eb99879 https://zh.wikipedia.org/wi ...

  5. C#制作、打包、签名、发布Activex全过程【转】

    http://www.cnblogs.com/still-windows7/p/3148623.html 一.前言 最近有这样一个需求,需要在网页上面启动客户端的软件,软件之间的通信.调用,单单依靠H ...

  6. 将可执行程序的内存空间扩展到3GB(windows)

    为了告知操作系统这个应用程序可以支持/3GB方式,我们需要往exe 文件头中添加一个 IMAGE_FILE_LARGE_ADDRESS_AWARE 标志.添加的方式很简单: 在你的系统的 Progra ...

  7. 【翻译自mos文章】使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法

    使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法 參考原文: How to Copy asm files between remote ASM instances usi ...

  8. python(2)- python程序的编写简单介绍

    一.语句和语法 # 注释 \ 转译回车,继续上一行,在一行语句较长的情况下可以使用其来切分成多行,因其可读性差所以不建议使用 : 将两个语句连接到一行,可读性差,不建议使用 : 将代码的头和体分开 语 ...

  9. FastDFS的配置、部署与API使用解读(6)FastDFS配置详解之Storage配置(转)

    1 基本配置 disabled #func:该配置文件是否生效 #valu: ## true:无效 ## false:生效 disabled=false group_name #func:本stora ...

  10. Fckeditor常见漏洞的挖掘与利用整理汇总

    查看编辑器版本号 FCKeditor/_whatsnew.html ------------------------------------------------------------- 2. V ...