AcWing 1204. 错误票据
原题链接
简单
作者:
Lucky.
,
2021-05-29 14:35:39
,
所有人可见
,
阅读 315
C++ 代码
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10,INF = 0x3f3f3f3f;
int n;
int cnt[N];
int main()
{
int m = INF,M = -INF;
cin >> n;
n++;
while( n -- )
{
string t,line;
getline(cin,line);
stringstream ss;
ss << line;
while(ss >> t)//###以空格为界限将字符串分开
{
int num = stoi(t);
m = min(m,num);//找出最大值
M = max(M,num);//找出最小值
cnt[num]++;
}
}
int resa,resb;
for(int i = m; i <= M; i++)
{
if(cnt[i] == 0) resa = i;
if(cnt[i] == 2) resb = i;
}
cout << resa << " " << resb << endl;
return 0;
}