校赛E 统计

来源:互联网 发布:淘宝站外网站 编辑:程序博客网 时间:2024/06/08 18:23
Description

Youcai Li is a student and he like to chat with girls usually. In order to know which girl he talked with, he numbers these girls, so each girl has her own individual number. For instance, Miss.Leilei Wang's number is 1. Miss.Xiaolei Wang's number is 2.


Input

All input numbers are integers.

The first line is a integer n (1 <= n <= 105 )means how many times Mr.Li talk with girls.

Next line contains n integers representing the number of girls. ( 1 <= numberi <= 88888888)


Output

Can you tell me which girl Mr.Li talk with the most frequently? please output two integers:

represent the number of the girl.

m reoresent how many times Mr.Li talk with the girl.


Sample Input
10
8 7 5 4 9 1 5 5 4 1
Sample Output
5 3
HINT

In this sample, Mr.Li talk with 5th girl most frequently and he talk with the girl for 3 times!



这题是英文题,题目比较水,只要能翻译正确,基本上没什么太大的问题。大概意思就是输入n,代表输入n个数,在输入的数里面找出出现此数的数,输出这个数,并且输出这个数出现的次数。这题可以直接选用sort排序。

#include<stdio.h>#include<algorithm>#include<iostream>using namespace std;int a[110000];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int i,temp=1,max=0,m;//因为出现的数字次数最少是1,所以temp为1        for(i=0;i<n;i++)            scanf("%d",&a[i]);        sort(a,a+n);        for(i=0;i<(n-1);i++)        {            if(a[i]==a[i+1])                temp++;//如果后面的数等于前面的数,则temp加1.            else                temp=1;//如果不等于,重置temp.            if(max<=temp)            {                max=temp;                m=i;            }        }        printf("%d %d\n",a[m],max);    }    return 0;}


0 0