http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1480

#include <stdio.h>
#include <string.h>
int n;
#define N 100001  //N的值取比哈希表长度略大的(质数)
int a[100001],b[100001];
int main()
{
    int i,j,ad,t;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
      scanf("%d",&t);
      ad=t%N;
      if(ad<0) ad=ad+N;
      while(1)
      {
         if(a[ad]==0||a[ad]==t)
         {
            a[ad]=t;
            b[ad]++;
            break;
         }
         else
         {
            ad++;
            if(ad>=N) ad=0;
         }
      }
    }
      int max=b[0];
      t=0;
      for(i=1;i<N;i++)
      {
          if(max<b[i]||(max==b[i]&&a[t]>a[i]))
          {
            max=b[i];
            t=i;
          }
      }
      printf("%d %d\n",a[t],max);



    return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.