zoukankan      html  css  js  c++  java
  • hdu 1004

    自从   暑假 ACM集训之后就再也没有碰过  ACM了   以前说出去的话都是泼出去的水啊  哈哈哈  

    水一道题啊   一年过去了   

    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
     
     
    思路就是:一个字符型二维数组用来存颜色,一个一维整数型数组用了存颜色出现的次数。之后再拿第一个颜色扫一遍,遇见相同的count++,再拿第二个颜色扫一遍,这个用两个for语句。        菜的抠脚啊     水不出来还是抄到其他人的思路的......
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 int main()
     4 {
     5     int n,max,i,j;
     6     char a[1000][15],b[1000];
     7     while(scanf("%d",&n)&&n)
     8     {
     9         for(i=0; i<n; i++)
    10         {
    11             scanf("%s",&a[i]);
    12             b[i]=0;
    13         }
    14         for(i=0; i<n; i++)
    15         {
    16             for(j=i+1;j<n;j++)
    17                 if(strcmp(a[i],a[j])==0)
    18                     b[i]++;
    19         }
    20         max=0;
    21         for(i=0;i<n;i++)
    22             if(max<b[i])
    23                 max=i;
    24         printf("%s
    ",a[max]);
    25     }
    26     return 0;
    27 }
  • 相关阅读:
    CSS3相关编码规范
    WEB开发中常见的漏洞
    Python常用端口扫描
    33、Django实战第33天:我的消息
    32、Django实战第32天:我的收藏
    31、Django实战第31天:我的课程
    30、Django实战第30天:修改邮箱和用户信息
    29、Django实战第29天:修改密码和头像
    28、Django实战第28天:个人信息展示
    27、Django实战第27天:全局搜索功能开发
  • 原文地址:https://www.cnblogs.com/huangguodong/p/5510133.html
Copyright © 2011-2022 走看看