HDU

来源:互联网 发布:善领p46最新数据 编辑:程序博客网 时间:2024/06/02 00:28

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5166

题目描述

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 (n) , which means the number of numbers the permutation has. In following a line , there are nn distinct postive integers.(1≤n≤1,0001≤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

解题思路

题意是要补全第二行中的数字,使它连续,如果要添加的数有多种情况的话,输出小数,
因为是从 1 开始的,所以数据不大,直接用桶标记,即mark数组,用flag标记输出的个数,从1开始遍历,优先输出小的
注意第二次要初始化mark数组

AC代码

#include<iostream>#include<cmath>#include<cstring>using namespace std;int main () {    int t;    int a;    int mark[1010];    cin >> t;    while(t--) {        int n;        cin >> n;        memset(mark, 0, sizeof(mark));        for(int i = 0; i < n; i++) {            cin >> a;            mark[a] = 1;        }        int flag = 0;        int i = 1;        while(flag <= 1) {            if(mark[i] == 0) {                if(flag == 0) printf("%d ", i);                else if(flag == 1) printf("%d\n", i);                flag++;            }            i++;        }    }    return 0;}
原创粉丝点击