栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

电话聊天狂人Java

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

电话聊天狂人Java

编程语言:Java
题目:

题解:不超时需要用技巧。
结果:AC

import java.io.*;
import java.util.*;
public class Main {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static Scanner sc = new Scanner(new BufferedInputStream(System.in));



    public static void main(String[] args) throws IOException {
        in.nextToken();
        int n= (int) in.nval;
        Map map=new LinkedHashMap<>();
        String t;
        for(int i=0;i
            in.nextToken();
            t=in.nval+"";
            if(map.containsKey(t))
                map.put(t,(int)map.get(t)+1);
            else
                map.put(t,1);
            in.nextToken();
            t=in.nval+"";
            if(map.containsKey(t))
                map.put(t,(int)map.get(t)+1);
            else
                map.put(t,1);
        }
        int sum=0;
        int num=0;
        String res="";
        Iterator> entries = map.entrySet().iterator();
        while(entries.hasNext()){
            Map.Entry entry = entries.next();
            if(entry.getValue()>sum){
                res=entry.getKey();
                num=1;
                sum=entry.getValue();
            }else if(entry.getValue()==sum){
                num++;
                if(res.compareTo(entry.getKey())>0){
                    res=entry.getKey();
                }
            }
        }
        res=res.substring(0,1)+res.substring(2,12);
        if(num==1){
            out.println(res+" "+sum);
        }else{
            out.println(res+" "+sum+" "+num);
        }
        out.flush();
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/874379.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号