給定大量手機用戶通話記錄,找出其中通話次數最多的聊天狂人。
輸入格式:
輸入首先給出正整數N(≤105),爲通話記錄條數。隨後N行,每行給出一條通話記錄。簡單起見,這裏只列出撥出方和接收方的11位數字構成的手機號碼,其中以空格分隔。
輸出格式:
在一行中給出聊天狂人的手機號碼及其通話次數,其間以空格分隔。如果這樣的人不唯一,則輸出狂人中最小的號碼及其通話次數,並且附加給出並列狂人的人數。
輸入樣例:
4
13005711862 13588625832
13505711862 13088625832
13588625832 18087925832
15005713862 13588625832
輸出樣例:
13588625832 3
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
int n;
cin >> n;
long long s1,s2;
map<long long,int>data;
while(n--)
{
cin >> s1 >> s2;
if(!data.count(s1))data[s1] = 1;
else data[s1]++;
if(!data.count(s2))data[s2] = 1;
else data[s2]++;
}
map<long long,int>::iterator it = data.begin();
long long res;
int cnt = -1;
int count = 0;
while(it != data.end())
{
if(it->second > cnt)
{
res = it->first;
cnt = it->second;
count = 1;
}
else if(it->second == cnt)
{
count++;
}
it++;
}
cout << res << " " << cnt;
if(count != 1) cout << " " << count;
}