HDU 1029 Ignatius and the Princess IV 【求众数】

看题目觉得还挺奇怪的,后来反应过来其实是求一堆数字的众数。。。。

最近做题真是越来越懒了。。。= = 有木有人可以监督我唉%>_<%

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 int main(){
 5     int n, num[50000], tem, i, j;
 6     while(scanf("%d",&n) != EOF){
 7         memset(num, 0, sizeof(num));
 8         for(i = 1; i <= n; i++){
 9             scanf("%d",&tem);
10             num[tem]++;
11             if(num[tem] >= (n + 1) / 2)
12                 j = tem;
13         }
14         printf("%d
",j);
15     }
16     return 0;
17 }
Everything will be ok in the end. If it is not ok then it is not the end.
原文地址:https://www.cnblogs.com/shirleytian/p/3292075.html