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 }
  • 相关阅读:
    document.body.scrollTop or document.documentElement.scrollTop
    获取到body的offsetTop和offsetLeft值
    Web安全学习笔记之一
    angular.js学习笔记之一
    backbone学习笔记一
    IE中的CSS3不完全兼容方案
    c#调用c++库函数
    c++动态库封装及调用(3、windows下动态库调用)
    c++动态库封装及调用(2、windows下动态库创建)
    c++动态库封装及调用(1、动态库介绍)
  • 原文地址:https://www.cnblogs.com/huangguodong/p/5510133.html
Copyright © 2011-2022 走看看