1. 给你一个chatting log file,format大概是这样的:
A: bla
B: bla bla
C: bla bla bla
要你找出说话最多(看word number) 的K个人
而且代码要从读file开始写
/*
1. 给你一个chatting log file,format大概是这样的:
A: bla
B: bla bla
C: bla bla bla
要你找出说话最多(看word number) 的K个人
而且代码要从读file开始写 */
public class Main {
public static void main(String[] args) {
List<String> lines =new ArrayList<>();
lines.add("A: bla");
lines.add("A: bla");
lines.add("B: bla bla");
lines.add("C: bla bla bla");
lines.add("A: bla"); List<String> list = new Solution().findMostPeopleTest(lines);
for(String name : list){
System.out.println(name);
}
}
} class Solution{
/*
public List<String> findMostPeople (String filePath) throws Exception {
HashMap<String, Integer> map = new HashMap<>();
int maxCounts = 0;
List<String> list = new ArrayList<>();
//read from file
File file = new File(filePath);
BufferedReader br = new BufferedReader(new FileReader(filePath));
String st;
while((st = br.readLine()) != null){
//can be replaced by other string related functions
String[] strs = st.split(": ");
String name = strs[0];
String[] words =strs[1].split(" ");
int wordsCount = words.length;
int totalCounts = map.getOrDefault(name, 0)+wordsCount;
map.put(name, totalCounts);
if(totalCounts > maxCounts){
list.clear();
list.add(name);
}
else if (totalCounts == maxCounts){
list.add(name);
}
}
return list;
}
*/
public List<String> findMostPeopleTest (List<String> lines) {
HashMap<String, Integer> map = new HashMap<>();
int maxCounts = 0;
List<String> list = new ArrayList<>();
//read from file
//File file = new File(filePath);
//BufferedReader br = new BufferedReader(new FileReader(filePath));
for(String st : lines){
//can be replaced by other string related functions
String[] strs = st.split(": ");
String name = strs[0];
String[] words =strs[1].split(" ");
int wordsCount = words.length; int totalCounts = map.getOrDefault(name, 0)+wordsCount;
System.out.println(name + " : "+totalCounts);
map.put(name, totalCounts);
if(totalCounts > maxCounts){
list.clear();
list.add(name);
maxCounts = totalCounts;
}
else if (totalCounts == maxCounts){
list.add(name);
}
}
return list;
} }

Google - Find Most People in Chat Log的更多相关文章

  1. Google glog 使用

    Google glog 使用 1        简介 Googleglog 库实现了应用级的日志记录,提供了C++ 风格的流操作和各种助手宏. 代码示例: #include <glog/logg ...

  2. Python + logging 输出到屏幕,将log日志写入文件

    日志 日志是跟踪软件运行时所发生的事件的一种方法.软件开发者在代码中调用日志函数,表明发生了特定的事件.事件由描述性消息描述,该描述性消息可以可选地包含可变数据(即,对于事件的每次出现都潜在地不同的数 ...

  3. 百度Apollo解析——2.log系统

    Apollo中的glog 在Apollo中google glog 被广泛使用,glog 是 google 的一个 c++ 开源日志系统,轻巧灵活,入门简单,而且功能也比较完善. 1. 安装 以下是官方 ...

  4. Python + logging输出到屏幕,将log日志写入到文件

    logging提供了一组便利的函数,用来做简单的日志.它们是 debug(). info(). warning(). error() 和 critical(). logging函数根据它们用来跟踪的事 ...

  5. c++ google glog模块安装和基本使用(ubuntu)环境

    1,如何安装 1 Git clone https://github.com/google/glog.git 2 cd glog 3 ./autogen.sh 4 ./configure --prefi ...

  6. Blazor组件自做五 : 使用JS隔离封装Google地图

    Blazor组件自做五: 使用JS隔离封装Google地图 运行截图 演示地址 正式开始 1. 谷歌地图API 谷歌开发文档 开始学习 Maps JavaScript API 的最简单方法是查看一个简 ...

  7. VBV Rate Control

    Part 1 <06/05/07 12:08pm> Manao | he is negating a float by printing it, adding a "-" ...

  8. python自动化运维之路~DAY5

    python自动化运维之路~DAY5 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.模块的分类 模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数 ...

  9. How to calculate bits per character of a string? (bpc) to read

      http://stackoverflow.com/questions/17797922/how-to-calculate-bits-per-character-of-a-string-bpc up ...

随机推荐

  1. css 两端对其

    大段的文字直接写会有不整齐的现象  所以ui小姐姐就会和我们讲你能不能把两端对其呀  ps里面就可以呀 okok  那就两端对其好了 text-align:justify 效果为⬇️⬇️⬇️  上面是 ...

  2. python 警惕 IEEE 754标准

    双精度浮点数格式,即IEEE 754标准 >>> 0.1+0.2 0.30000000000000004 >>> (0.1+0.2)==0.3 False > ...

  3. C#实现基于ffmpeg加虹软的人脸识别

    关于人脸识别 目前的人脸识别已经相对成熟,有各种收费免费的商业方案和开源方案,其中OpenCV很早就支持了人脸识别,在我选择人脸 识别开发库时,也横向对比了三种库,包括在线识别的百度.开源的OpenC ...

  4. chrome 调试功能使用说明

    单文件搜索 ctrl+f 全局搜索 ctrl+shift+f

  5. box-sizing 和 dom width

    refer : https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions ...

  6. border——边框属性

    一.第一层次(复合样式) <style> p.one{border:1px solid black;} /*边框:1像素 实心的 黑色:*/ </style> <body ...

  7. UI 增加文本

    1.直接在节点上增加VALUE NODE. 2.写GET,SET,I,P的相关实现 method GET_ZH12. DATA: lr_current TYPE REF TO if_bol_bo_pr ...

  8. 码云git使用五(创建远程分支和更新远程分支)

    1.创建一个与远程分支没有关联的本地分支 2.从远程拉取到本地分支 3.创建远程分支() 4.搞定了.

  9. shell脚本结构

    echo $? 代表上一次命令的状态返回值,‘0’则代表为真<执行成功>,‘非零’则代表为假<执行失败>. shell脚本: <判断老男孩的年纪> [root@bo ...

  10. 面试题--Java

    &与&&区别? &与&&都是逻辑运算符,都是判断两边为真则为真,两边为假则为假,但是&&如果第一个条件不成立的话,后面的将不会再继续执行 ...