poj2092

 1 /*水题,算每个号码处出现的次数*/
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 const int maxn=10000+10;
 7 struct point
 8 {
 9     int num,index;
10 }p[maxn];
11 int cmp(const point a,const point b)
12 {
13     if(a.num==b.num) return a.index<b.index;
14     return a.num>b.num;
15 }
16 int hash[maxn];
17 int main()
18 {
19     int i,j,n,m,k;
20     int t;
21     while(scanf("%d%d",&n,&m)!=EOF)
22     {
23         if(n==0 && m==0) break;
24         memset(hash,0,sizeof(hash));
25         memset(p,0,sizeof(p));
26         int N=n*m;
27         int MAX=0;
28         int x;
29         for(i=0;i<N;i++)
30         {
31             scanf("%d",&x);
32             hash[x]++;
33             if(x>MAX) MAX=x;
34         }
35         k=0;
36         for(i=1;i<=MAX;i++)
37         {
38             if(hash[i])
39             {
40                 p[k].num=hash[i];
41                 p[k].index=i;
42                 k++;
43             }
44         }
45         sort(p,p+k,cmp);
46         int s=p[0].num;
47          int in;
48          for(i=0;i<k;i++)
49          {
50              if(p[i].num<s)
51              {
52                  s=p[i].num;
53                  in=i;
54                  break;
55              }
56          }
57          printf("%d",p[in].index);
58          for(i=in+1;i<k;i++)
59          {
60              if(p[i].num==s)
61              {
62                  printf(" %d",p[i].index);
63              }
64          }
65          printf("
");
66     }
67     return 0;
68 }
69 
70 
71 
72 
73 
74 
75 
76 
77             
78 
79             
80             
原文地址:https://www.cnblogs.com/okboy/p/3223885.html