import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.nextLine().trim(); int n=0; //下行输入n个数字,注意系统给的数字不一定为n个,可能少个n. 只要数量 num>=(n+1)/2 就行。 if(!str.equals("")) n=Integer.parseInt(str); TreeMap<Integer,Integer>arr=new TreeMap<>(); int index=0; String[]s=sc.nextLine().trim().split(" "); for (int j = 0; j < s.length; j++) { int cnt=0 ; int a=Integer.parseInt(s[j]); if(arr.containsKey(a)){ cnt=arr.get(a); arr.put(a, cnt+1);} else arr.put(a, 1); if(cnt+1>=(n+1)/2){index=a; break;} } System.out.println(index); } sc.close(); } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:909 |
C语言程序设计教程(第三版)课后习题7.2 (Java代码)浏览:686 |
简单的a+b (C语言代码)浏览:647 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:1450 |
兰顿蚂蚁 (C++代码)浏览:1091 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:557 |
字符逆序 (C语言代码)浏览:646 |
矩形面积交 (C语言代码)浏览:1313 |
链表数据求和操作 (C语言代码)浏览:952 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:476 |