結果
問題 | No.79 過小評価ダメ・ゼッタイ |
ユーザー |
![]() |
提出日時 | 2017-09-24 15:22:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 593 ms / 5,000 ms |
コード長 | 933 bytes |
コンパイル時間 | 3,281 ms |
コンパイル使用メモリ | 82,612 KB |
実行使用メモリ | 48,584 KB |
最終ジャッジ日時 | 2024-06-26 08:18:51 |
合計ジャッジ時間 | 11,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; public class Main{ public static void main(String args[])throws Exception{ Scanner sc=new Scanner(System.in); HashMap<Integer,A>map=new HashMap<Integer,A>(); int n=Integer.parseInt(sc.nextLine()); for(int i=0;i<n;i++){ int m=sc.nextInt(); if(map.containsKey(m)==false){ map.put(m,new A(m)); }else{ map.get(m).num++; } } LinkedList<A>queue=new LinkedList<A>(map.values()); Collections.sort(queue,new Comparator<A>(){ public int compare(A a1,A a2){ if(a1.num != a2.num) return a1.num-a2.num; else return a1.value-a2.value; } }); System.out.println(queue.getLast().value); } } class A{ int num; int value; public A(int value){ this.value=value; this.num=1; } public String toString(){ return this.value+":"+this.num; } }