Telephone madman
Title Description
Given a large number of mobile phone users call records to find out where the most number of calls chat madman.
Entry
Firstly, input a positive integer N (≤105), the number of records for the call. Then N lines of a given call record. For simplicity, just to name a dialed phone number and the recipient's 11 digit number, wherein separated by spaces.
4
13005711862 13588625832
13505711862 13088625832
13588625832 18087925832
15005713862 13588625832
Export
Maniac given chat phone number in a row and the number of calls, separated by a space therebetween. If such a person is not unique, the minimum number and the number of calls in a madman output, and given the additional number of parallel madman.
13588625832 3
Thinking
Telephone number is very long, with the long long storage type, a first row of the array sequence, then find their number
Code
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long a[220],b[220];//不带要删除了,就整了两个数组
int n,j=0,num[220]={1},max=0;
cin>>n;
for(int i=0;i<2*n;i++)
{
cin>>a[i];
}
fill(num,num+2*n,1); //现将计数数组全部赋值为1
sort(a,a+2*n); //排序,这样更好找一样的号码
for(int i=0;i<2*n;i++) //计数
{
b[j]=a[i];
if(a[i+1]==a[i])
{
num[j]++;
}
else
{
j++;
}
}
for(int i=0;i<2*n;i++) //求最大的数
{
if(num[i]>max)
{
max=num[i];
}
}
for(int i=0;i<2*n;i++) //以防出现多个数量一样的号码
{
if(num[i]==max)
{
cout<<b[i]<<" "<<num[i]<<endl;
}
}
return 0;
}