AcWing 1204. 错误票据
原题链接
简单
作者:
hegehog
,
2020-07-08 23:10:20
,
所有人可见
,
阅读 620
C++代码(stringstream)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
typedef long long ll;
const int INF = 1e8;
const int N = 100005;
int cnt[N];
int n;
int main()
{
int a;
string s;
int maxn = -INF, minn = INF;
cin >> n;
getline(cin, s);//读一个换行
while(n--){
getline(cin,s);//默认到换行符截止
stringstream sin;//声明一个流的输入输出类
sin << s;//将s的内容放入流
while(sin >> a){//将流中的值放入a
cnt[a]++;
if(a > maxn) maxn = a;
if(a < minn) minn = a;
}
}
int x, y;
for(int i = minn; i < maxn; i ++)
{
if(cnt[i] > 1) x = i;
else if(cnt[i] == 0) y = i;
}
cout << y << " " << x << endl;
return 0;
}