zoukankan      html  css  js  c++  java
  • 【杭电ACM】1004 Let the Balloon Rise

    开始写技术博客了。

    发发自己写的ACM的练习题。

     杭电ACM1004    Let the Balloon Rise

     http://acm.hdu.edu.cn/showproblem.php?pid=1004

     

    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 //author:pz
     2 
     3 import java.util.ArrayList;
     4 import java.util.Scanner;
     5 
     6 public class Main{
     7 
     8   public static void main(String args[]){
     9   Scanner scan = new Scanner(System.in);
    10   while(scan.hasNextInt()){
    11     int n = scan.nextInt();
    12     if(n == 0)
    13       break;
    14     ArrayList<String> color = new ArrayList<String>();
    15     ArrayList<Integer> count = new ArrayList<Integer>();
    16     String c = scan.next();
    17     color.add(c);
    18     count.add(1);
    19     String modeColor=c;
    20     Integer modeCount=1;
    21     while(--n > 0){
    22       String s = scan.next();
    23       if(color.contains(s)){
    24         count.set(color.indexOf(s),count.get(color.indexOf(s))+1);
    25         if(count.get(color.indexOf(s)) > modeCount){
    26           modeColor = s;
    27           modeCount = count.get(color.indexOf(s));
    28         }
    29       }
    30       else{
    31         color.add(s);
    32         count.add(1);
    33       }
    34     }
    35     System.out.println(modeColor);
    36   }
    37   }
    38 }
     
  • 相关阅读:
    Android笔记之开机自启
    Android笔记之广播
    Hive笔记之collect_list/collect_set(列转行)
    Hive笔记之数据库操作
    hive笔记之row_number、rank、dense_rank
    Linux Shell管道调用用户定义函数(使shell支持map函数式特性)
    Linux shell爬虫实现树洞网鼓励师(自动回复Robot)
    分享一些免费的接码平台(国外号码)
    爬虫技能之内容提取:如何从有不可见元素混淆的页面中抽取数据
    ctf writeup之程序员密码
  • 原文地址:https://www.cnblogs.com/pengzheng/p/3009244.html
Copyright © 2011-2022 走看看