zoukankan      html  css  js  c++  java
  • Let the Balloon Rise

    原创


      题目要求从给出的N个字符串中找出出现次数最多的,所以完成统计功能存储输出就可以了;每输入一个字符串就拿当前字符串str2和

    之前的字符串strx相比,相同则将统计数组加1(value[strx]++),然后再从统计数组中找出最大值,存储索引指向的字符串即可。

    Java AC

     1 import java.util.*;
     2 
     3 public class HDOJ_1004 {
     4 
     5     public static void main(String[] args) {
     6         Scanner reader=new Scanner(System.in);
     7         ArrayList list=new ArrayList();
     8         int count=-1;
     9         while(reader.hasNext()) {
    10             int N=reader.nextInt();
    11             if(N==0) {
    12                 break;
    13             }
    14             String str[]=new String[N];
    15             int value[]=new int[N];
    16             for(int i=0;i<N;i++) {
    17                 str[i]=reader.next();
    18                 for(int j=0;j<i;j++) {
    19                     if(str[i].equals(str[j])==true) {    //判断此字符串与前面字符串是否相等
    20                         value[j]++;
    21                     }
    22                 }
    23             }
    24             //寻找最大值
    25             int index=0;
    26             int max=-1;
    27             for(int i=0;i<N;i++) {
    28                 if(value[i]>max) {
    29                     max=value[i];
    30                     index=i;
    31                 }
    32             }
    33             list.add(str[index]);
    34             count++;
    35         }
    36         for(int i=0;i<=count;i++) {
    37             System.out.println(list.get(i));
    38         }
    39     }
    40 
    41 }

    16:36:54

    2018-08-20

  • 相关阅读:
    axios拦截器
    Vue路由守卫
    HTML横向滚动条和文本超出显示三个小圆点
    Vue用户名vuex和localStorage双向存储
    javaScript Es6数组与对象的实例方法
    使用vue实现复选框单选多选
    正则表达式常用字符
    jest函数单元测试
    ts中的类
    ts中接口的用法
  • 原文地址:https://www.cnblogs.com/chiweiming/p/9506375.html
Copyright © 2011-2022 走看看