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