编程介的小学生 2017-12-02 06:55 采纳率: 20.5%
浏览 995
已采纳

Let the Balloon Rise

Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you.

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0

Sample Output
red
pink

  • 写回答

1条回答 默认 最新

  • bestsort 2017-12-02 07:01
    关注

    #include
    #include
    #include
    #define maxn 1005
    #define MAXN 20
    int cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
    }
    int main(int argc, char *argv[])
    {
    char balloon[maxn][MAXN];
    int n,i,k;
    int num;
    int cnt[maxn];
    int max;
    char res[MAXN];
    while(1){
    scanf("%d",&n);
    if(n == 0)
    break;
    k = 0;
    max = 0;
    num = 0;
    for(i = 0;i < n;i++)
    scanf("%s",balloon[i]);
    qsort(balloon,n,sizeof(balloon[0]),cmp);
    for(i = 1;i < n;i++){
    if(strcmp(balloon[i],balloon[i - 1]) == 0){
    num++;
    if( max < num)
    max = k+num-1;
    }
    else k++,
    num =0;
    }
    printf("%s\n",balloon[max]);}

    return 0;
    

    }

    zoj已A

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度