Problem1837--【串与数组】4-14 查找数组中缺失的数字

1837: 【串与数组】4-14 查找数组中缺失的数字

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

在大小为n的数组中,仅存在大小为[1,n]的数字,数组中的元素有些出现了两次,有些出现了一次,有的数字没有出现。设计一个算法在空间复杂度为O(1),时间复杂度为O(n)的情况下找到这些没有出现的数字。假设储存结果的数组不算在额外空间之内。

Input

多组数据,每组数据有两行,第一行为数组的长度n,第二行为数组的n个元素(元素之间用空格分隔),当n=0时输入结束。

Output

对于每组数据分别输出一行,输出缺失的数据(元素之间用空格分隔),如果数据未缺失,输出Not Found。

Sample Input Copy

8
4 3 2 7 8 2 3 1
6
1 4 2 6 2 4
6
3 2 2 1 3 4
5
1 2 3 4 5
0

Sample Output Copy

5 6
3 5
5 6
Not Found

HINT

#include<iostream>
#include<string>
#include<cmath>
#define MAXSIZE 1024
using namespace std;
void FindMissNumber(int *a,int n)
{//指定数字组中的位数
/**************begin************/




    /**************end************/
}
int main()
{
    int n;
    while (cin>>n)
    {
        if(n==0) break;
        int *a=new int[MAXSIZE]{0};    //初始编号集合中的所有元素都小于0
        for(int i=0;i<n;i++)            //将输入数据输入数据组
        {
            cin>>a[i];
        }
        FindMissNumber(a,n);
    }
    return 0;
}

Source/Category