C++
$\color{gold}{— > 蓝桥杯辅导课题解}$
法一:
思路:
模拟
$1、通过min1,max1记录票据范围,a数组记录票据id出现次数$
$2、遍历,a[i]为0:断号,a[i]大于1:重号$
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
int x, min1, max1;
int x1, y1;
int main() {
cin >> n;
while (cin >> x) { // 不断读入直到结束
min1 = min(min1, x);
max1 = max(max1, x);
a[x] ++;
}
for (int i = min1; i <= max1; i ++) {
if (a[i] == 0) x1 = i;
if (a[i] > 1) y1 = i;
}
cout << x1 << ' ' << y1;
return 0;
}
法二:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
int main() {
int cnt;
cin >> cnt;
string line;
getline(cin, line); // 忽略掉第一行的回车
while (cnt --) {
getline(cin, line);
stringstream ssin(line); // 类似于 scanf("%s", )
while (ssin >> a[n]) n ++;
}
sort(a, a + n);
int res1 = 0, res2 = 0;
for (int i = 1; i < n; i ++)
if (a[i] == a[i - 1]) res2 = a[i]; // 重号
else if (a[i] >= a[i - 1] + 2) res1 = a[i] - 1; // 断号
cout << res1 << ' ' << res2;
return 0;
}