NYOJ 254 编号统计

地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=254

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #define N 200010
 4 int a[N];
 5 int cmp(void const *a,void const *b)
 6 {
 7     return *(int *)a-*(int *)b;
 8 }
 9 int main()
10 {
11     int T,max,count,maxnum,n,i;
12     scanf("%d",&T);
13     while(T--)
14     {
15         scanf("%d",&n);
16         for(i=0;i<n;i++)
17             scanf("%d",&a[i]);
18         qsort(a,n,sizeof(int),cmp);
19         for(i=1,max=a[0],count=1,maxnum=1;i<n;i++)
20         {
21             if(a[i]==a[i-1])
22             {
23                 count++;
24                 if(count>maxnum) 
25                 {
26                     maxnum=count;
27                     max=a[i-1];
28                 }
29                     
30             }
31             else count=1;        
32         }
33         printf("%d\n",max);
34     }
35     //system("pause");
36     return 0;
37 }
   

posted on 2012-08-13 21:24  mycapple  阅读(163)  评论(0编辑  收藏  举报

导航