ACM比赛(第二次A)

ime Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 \leq 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 \leq n \leq 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

程序分析:此题如果不理解意思可能会觉得比较难,但是如果理解了可能就觉得还好。他的意思就是先输入案例数,在输入下一个数组的元素个数,最后输入数组。然后输出这个数组没有出现的最小两个数。

解题思路:先把用 memset(x,0,sizeof(x))将数组X清0,然后每次输入一个数就用 x[temp]++这条语句令它为1,最后在从1开始判断这个数是否出现过,如果没出现就输出。然后C++,如果C=2时结束。if(c==1)cout<<" "这条语句很好的处理了输出完第一个数空格,输出完第二个数就结束。如果直接用cout<<i<<" ";就会出现每输出完一个数就有一个空格导致编译通不过。

#include<iostream>
#include<cstring>
using namespace std;
int x[10006];
int main(){
    int t;cin>>t;
    while(t--){
        memset(x,0,sizeof(x));
        int t1,temp;cin>>t1;
        for(int i=0;i<t1;i++){
            cin>>temp;
            x[temp]++;
        }
        int c=0;
        for(int i=1;c<2;i++){
            if(x[i]==0){
                c++;
                cout<<i;
                if(c==1)cout<<" ";
            }
        }
        cout<<endl;
    }
return 0;
}
posted @ 2015-07-17 15:45  lee是美少女  阅读(164)  评论(0编辑  收藏  举报