转自: http://blog.csdn.net/u010126535/article/details/21036263
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<stack>
#include<queue>
#include <iomanip>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std ;
/*
因为有多行输入,且每行的输入数据个数不一,所以可以考虑运用#include<sstream> 中的stringstream 流
现将每行输入存储在string s中,然后将s流入 stringstream ss中 ,然后从ss中依次按整形读取整数,存入整形数组中
*/
int main()
{
int n,duan,chong;
int a[100000];
int Max=0 ,Min=9999999 ;
string s ;
scanf("%d",&n);
getchar();
while(n--)
{
getline(cin,s);
stringstream ss ;
ss << s ; //注意流方向,把字符串输入ss流中
int x; //注意从stringstream中解析对象的时候,是以空格和回车键为分隔符的
while( ss >> x ) //ss流中字符串转换为int 流出来 ;
{
a[x]++;
if( x > Max) Max=x;
if( x < Min) Min=x ;
}
}
for(int i = Min ; i <= Max ; i++ )
{
if(a[i]==0 && i!=Min)
duan=i ;
if(a[i]>1)
chong=i;
}
printf("%d %d\n",duan,chong);
return 0;
}