HDOJ 1004 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

题意:找输入的n组字符串出现次数最多的那个字符串,然后输出

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            if(n==0){
                return ;
            }
            //System.out.println("n="+n);
            int anumber[][] = new int[n][2];
            //初始化
            for(int i=0;i<n;i++){
                anumber[i][0] =0;
                anumber[i][1] =0;
            }
            String a[] = new String[n];
            for(int i=0;i<n;i++){
                a[i] = sc.next();
                //System.out.println("i="+i+","+a[i]);
            }

            for(int i=0;i<a.length-1;i++){
                for(int j=i+1;j<a.length;j++){
                    if(anumber[j][1]==0&&a[i].equals(a[j])){
                        anumber[j][1]=1;
                        anumber[i][0]++;
                    }
                }
            }
            int max = anumber[0][0];
            int k=0;
            for(int i=0;i<a.length;i++){
                if(anumber[i][0]>max){
                    max = anumber[i][0];
                    k=i;
                }
            }

            System.out.println(a[k]);

        }

    }

}
时间: 2024-10-13 08:33:37

HDOJ 1004 Let the Balloon Rise的相关文章

HDOJ 1004题 Let the Balloon Rise strcmp()函数

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

[ACMcoder] 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

HDOJ 1004

#include<stdio.h> #include<string.h> typedef struct//二维数组没有这个方便 { char str[16]; int num; }Node; int main() { Node col[1001]; int T,i,j,max; while(~scanf("%d",&T),T) { getchar(); for(i=1;i<=T;i++) col[i].num=0; for(i=1;i<=T;

HDOJ 1004(字符串分类统计)

#include<stdio.h> #include<string.h> typedef struct//二维数组没有这个方便 { char str[16]; int num; }Node; int main() { Node col[1001]; int T,i,j,max; while(~scanf("%d",&T),T) { getchar(); for(i=1;i<=T;i++) col[i].num=0; for(i=1;i<=T;

HDOJ1001-1005题解

1001--Sum Problem(http://acm.hdu.edu.cn/showproblem.php?pid=1001) #include <stdio.h> int sum(int n) { if(n % 2) return (n + 1) / 2 * n; else return (n / 2) * (n + 1); } int main() { int n; while(scanf("%d",&n) != EOF){ printf("%d\

vb的属性、方法和事件(一)

Visual Basic的窗体和控件是具有自己的属性.方法和事件的对象.可以把属性看作一个对象的性质,把方法看作对象的动作,把事件看作对象的响应.日常生活中的对象,如小孩玩的气球同样具有属性.方法和事件.气球的属性包括可以看到的一些性质,如它的直径和颜色.其它一些属性描述气球的状态(充气的或未充气的)或不可见的性质,如它的寿命.通过定义,所有气球都具有这些属性:这些属性也会因气球的不同而不同. 气球还具有本身所固有的方法和动作.如:充气方法(用氦气充满气球的动作),放气方法(排出气球中的气体)和

vba运行时错误1004怎么解决

  vba运行时错误1004怎么解决         在EXCEL这款软件中,有些用户使用到VBA,在一些测试中,偶尔会遇到软件的错误提示,比如错误1004.这通常是VBA就运行报错的结果,那么,vba运行时错误1004怎么解决呢?接下来小编就告诉大家vba运行时错误1004怎么办. 这段代码是测试当前VBA版本的: 复制代码 代码如下: Sub 获取VBA版本() MsgBox Application.VBE.Version End Sub 当按F5键,就报:运行时错误1004.经老师指点,单

杭电1004

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1004 参考代码: #include<stdio.h> #include <stdlib.h> #include <string.h> void main() { int i,n,j,max,tmp; char ctmp[16]; while (scanf("%d",&n)&&n) { char (*p)[16] = (char(

http-ios9 afnetworking请求数据 错误code=-1004

问题描述 ios9 afnetworking请求数据 错误code=-1004 真机iPad mini2,iOS9.1,已经在info.plist中增加 <key>NSAppTransportSecurity</key><dict> <key>NSAllowsArbitraryLoads</key> <true/></dict> 但是不起作用,怎么办呢啊!!!谢谢!!!!!! 解决方案 参考:http://www.ruan