算法
使用unordered_map
记录每个数的出现情况,如果多次出现则记录为重复值;同时对定义一个标记数组标记出现过的数字情况,并记录输入的min和max
,从小到大遍历一遍,若有st[i]=false
则说明该数未出现过。
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n;
bool st[N];
unordered_map<int,int> um;
int main()
{
cin>>n;
string str;
getline(cin,str);
int x = 0,y = 0,tmin = 99999999,tmax = -1;
while(n--)
{
getline(cin,str);
int t;
stringstream scin(str);
while(scin>>t)
{
st[t] = true;
tmin = min(tmin,t),tmax = max(tmax,t);
if(um[t]==0) um[t] = 1;
else y=t;
}
}
for(int i=tmin;i<=tmax;i++)
{
if(!st[i])
{
x = i;break;
}
}
cout<<x<<" "<<y<<endl;
return 0;
}