比赛--找丢失的数--解题报告T

  找丢失的数

题目大意:

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<=1000)
 

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开始。并且要从小到大输出。
程序代码:
 #include<cstdio>
#include<iostream>
using namespace std; const int maxn = ; int T[];
int n[];
int a[maxn]; int main ()
{
int T;
scanf("%d",&T);
while(T--){
int n,i;
memset(a,,sizeof(a));
scanf("%d",&n);
for( i=; i<n; i++ )
{
int m;
scanf("%d",&m);
a[m]=;
}
int f=;
for( i=;i<=n+;i++)
if(!a[i])
{
if (f)
{
cout<<i<<" ";
f=;
}
else
cout<<i;
}
cout<<endl;
}
return ;
}

心得:

这道题开始有一些思路,但是在写程序是遇到一些困难,后来百度了一下,发现用memset函数很简单,就又查了一些memset()的用法,知道了函数的作用是对较大的结构体或数组进行清零操作的一种快速方法。写这个程序学到了很多。

 
 
上一篇:node_nibbler:自定义Base32/base64 encode/decode库


下一篇:Samsung_tiny4412(驱动笔记01)----linux 3.5,U-Boot,Busybox,SD卡启动环境搭建