这个题就小题小做把,直接map vector走起。
如果把电话号码当作string读入,有超时的危险。
如果用长整型会稍微快一点。
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
map<ll, int> mp;
vector<ll> vt;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
if (mp[a]++ == 0) vt.push_back(a);
if (mp[b]++ == 0) vt.push_back(b);
}
ll ans;
int res = -1, cnt = 0;
for(int i = 0; i < (int)vt.size(); i++) {
if (mp[vt[i]] > res) {
res = mp[vt[i]];
ans = vt[i];
cnt = 1;
} else if (mp[vt[i]] == res) {
if (vt[i] < ans) ans = vt[i];
cnt++;
}
}
cout << ans << " " << res;
if (cnt > 1) cout << " " << cnt;
return 0;
}