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. [转载][FPGA]有限状态机FSM学习笔记(二)

    1. Mealy和Moore状态机的互换 对于给定的时序逻辑功能,可以用Mealy机实现,也可以用Moore机实现.根据Moore机比Mealy机输出落后一个周期的特性,可以实现两种状态机之间的转换. ...

  2. 【TJOI2017】可乐

    题目描述 加里敦星球的人们特别喜欢喝可乐.因而,他们的敌对星球研发出了一个可乐机器人,并且放在了加里敦星球的\(1\)号城市上.这个可乐机器人有三种行为:停在原地,去下一个相邻的城市,自爆.它每一秒都 ...

  3. layer的alert、prompt等操作如何响应键盘的回车和ESC操作

    layer.prompt({title: '请输入数据', formType: 1, //隐藏用户输入内容 // 这个是确定按钮的事件 "success":function(){ ...

  4. Linux进程调度(3):进程切换分析

     3.调度函数schedule()分析 当kernel/sched.c:sched_tick()执行完,并且时钟中断返回时,就会调用kernel/sched.c:schedule()完成进程切换.我们 ...

  5. css3 - 基本选择器

    有人说类选择器最好不要超过三层,其实我也是这样认为的,不是吗? 选择器分为四大类 标签.全选(相对于子类继承了0.1).类.ID 权值分别是:1->0.1->10->100(权值可叠 ...

  6. golang map to struct

    http://stackoverflow.com/questions/26744873/converting-map-to-struct func SetField(obj interface{}, ...

  7. solaris软件管理 FTP

    安装一些常用软件 一.应用程序与系统命令的关系: 系统命令文件位置在 /bin /sbin下面或为shell内部指令:完成对系统的基本管理工作:一般在字符操作界面中运行:一般包括命令字.命令选项和命令 ...

  8. 拒绝ssh远程暴力破解

    拒绝ssh远程暴力破解 简介 在网络技术日益发展的今天,网络上的安全问题日益严重.当你在公网上使用Linux服务器时,很有可能你的服务器正在遭受ssh暴力破解. 曾经有一次我的同伴将给客户提供监控服务 ...

  9. nodejs 模板字符串

    范例1: for (var i=0;i<10;i++){ var data = `公司名:${i}`; console.log(data) } 输出: 实例2: var name = '丁香医生 ...

  10. 实习日记 laravel怎么删除磁盘上的文件

    Storage 里面有 delete的方法 具体使用是 Storage::disk('uploads')->delete($fileName); 其中'uploads'是filesystem里面 ...