zoukankan      html  css  js  c++  java
  • who is the best?

    Description

    There are N people want to choose the best person. Each person select the best person $a_i$, .John wants to know that who received the most number of votes.      
                  

    Input

    The first line contains a single integer $T(1 leq T leq 50)$,indicating the number of test cases.        Each test case begins with an integer $N(1 leq N leq 100)$,indicating the number of person.        Next N lines contains an integer $a_i(1 leq a_i leq N)$.      
                  

    Output

    For each case, output an integer means who is the best person. If there are multiple answers, print the minimum index.      
                  

    Sample Input

    2 10 1 2 3 4 5 6 7 8 9 10 5 3 3 3 3 3
                  

    Sample Output

    1 3
     
     
     
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     int t,n,num,maxn;
     8     int a[1000];
     9     scanf("%d",&t);
    10     while(t--)
    11     {
    12         scanf("%d",&n);
    13         maxn=-1;
    14         memset(a,0,sizeof(a));
    15         for(int i=1;i<=n;i++)
    16         {
    17             scanf("%d",&num);
    18             a[num]++;
    19             if(a[num]>maxn)
    20             {
    21                 maxn=a[num];
    22             }
    23         }
    24         for(int i=1;i<=n;i++)
    25         {
    26             if(a[i]==maxn)
    27             {
    28                 printf("%d
    ",i);
    29                 break;
    30             }
    31         }
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    Extjs面板和布局初探
    XAMPP下apache部署网站,多个虚拟机(空间)配置
    安全配置织梦系统初探参考[转载]
    windows系统如何真正隐藏文件夹[转载]
    Siamese-RPN论文阅读
    线段树求和
    算法要点随记
    map使用示例
    算法准备之c++ sort使用示例
    编程要点随记
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4552740.html
Copyright © 2011-2022 走看看