7-27 找到出勤最多的人-hebust (10分)
根据教师的花名册,找到出勤最多的人。
输入格式:
出勤记录单行给出,数据直接使用空格分割。
输出格式:
单行输出(若有多人,人名直接使用空格分割,结尾处没有空格)。
输入样例:
在这里给出一组输入。例如:
zs ls ww ml zs ls ml zs ww
输出样例:
在这里给出相应的输出。例如:
zs
import java.util.HashMap;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
String s=in.nextLine();
String l[]=s.split(" ");
HashMap<String,Integer>h=new HashMap<>();
for(int i=0;i<l.length;i++) {
int m=0;
for(int j=0;j<l.length;j++) {
if(l[i].equals(l[j])) {
m++;
}
}
h.put(l[i], m);
}
int max=0;;
for(String str:h.keySet()) {
if(max<h.get(str))
max=h.get(str);
}
for(String str:h.keySet()) {
if(max==h.get(str))
System.out.println(str);
}
}
}