Missing number

题目:

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≤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
题意:
有一个长度为n+2的排列少了两数,找出这两个数,要求这两个数是最小的。
分析:
定义一个数组a,并且将它清零,如果数组中有数字x就将1赋值a[x],
后从i=1开始查找如果a[i]为零就将i输出。
说明:注意输出的格式和输出的个数。
 #include<iostream>
#include<cstring>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int T,n,x,j;
int b[];
cin>>T;
while(T--)
{
memset(a,,sizeof(a));
cin>>n;
for(int i=;i<n;i++)
{cin>>x;
a[x]=;
}
j=;
for(int k=;k<=n+;k++)
if(!a[k])
b[j++]=k;
cout<<b[]<<' '<<b[]<<endl;
}
return ;
}
 
 
 

最新文章

  1. Java学习手记2——多线程
  2. iOS CommonCrypto 对称加密 AES ecb,cbc
  3. 文件系统:Ext3和Ext4
  4. 错题802-java
  5. Topic Model
  6. 更新nvm
  7. 刀哥多线程之主队列gcd-06-main_queue
  8. CoreAnimation3-专用图层
  9. YII 小部件实现Area textArea
  10. iOS: 获取文件路径
  11. iOS 判断设备是否越狱
  12. IDEA中运行DirectKafkaWordCount程序
  13. socket编程解决粘包和丢包问题
  14. mongo 的导入和导出
  15. ulimit常用参数介绍
  16. LeetCode35.搜索插入位置
  17. CentOS7安装sogou输入法
  18. R &amp; ggplot2 &amp; Excel绘图(直方图/经验分布图/QQ图/茎叶图/箱线图)实例
  19. 《深入浅出WPF》读书笔记
  20. JS字符串补全方法padStart()和padEnd()

热门文章

  1. 手机web页面制作时的注意事项
  2. java Integer和int的拆箱与装箱
  3. IplImage, CvMat, Mat 的关系
  4. Arduino101学习笔记(八)&mdash;&mdash; 函数库
  5. indeterminateDrawable
  6. 【Web前端】---js调用本地应用程序
  7. java中的三种取整函数
  8. HDU 4821 String (HASH)
  9. Oracle 创建表空间一边串过程
  10. Spring Data JPA 查询方法支持的关键字