Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******
- * Read input from System.in
- * Use: System.out.println to ouput your result to STDOUT.
- * Use: System.err.println to ouput debugging information to STDERR.
- * ***/
- package com.isograd.exercise;
- import java.util.*;
- public class IsoContest {
- public static void main( String[] argv ) throws Exception {
- String line;
- Scanner sc = new Scanner(System.in);
- int n = 0;
- HashMap<String, Integer> couleurs = new HashMap<String, Integer>();
- while(sc.hasNextLine()) {
- line = sc.nextLine();
- if (n == 0) {
- n = Integer.parseInt(line);
- } else {
- if (couleurs.containsKey(line)) {
- couleurs.put(line, couleurs.get(line)+1);
- } else {
- couleurs.put(line, 1);
- }
- }
- }
- int max1 = 0, max2 = 0;
- String m1 = "", m2 = "";
- for (Map.Entry<String, Integer> pair: couleurs.entrySet()) {
- int c = pair.getValue();
- if (c > max1) {
- if (max1 > max2) {
- max2 = max1;
- m2 = m1;
- }
- max1 = c;
- m1 = pair.getKey();
- } else if (c > max2) {
- max2 = c;
- m2 = pair.getKey();
- }
- }
- System.out.println(m1 + " " + m2);
- /* Vous pouvez aussi effectuer votre traitement une fois que vous avez lu toutes les données.*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement