Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*******
  2. * Read input from System.in
  3. * Use: System.out.println to ouput your result to STDOUT.
  4. * Use: System.err.println to ouput debugging information to STDERR.
  5. * ***/
  6. package com.isograd.exercise;
  7. import java.util.*;
  8.  
  9. public class IsoContest {
  10. public static void main( String[] argv ) throws Exception {
  11. String line;
  12. Scanner sc = new Scanner(System.in);
  13.  
  14. int n = 0;
  15. HashMap<String, Integer> couleurs = new HashMap<String, Integer>();
  16.  
  17. while(sc.hasNextLine()) {
  18. line = sc.nextLine();
  19.  
  20. if (n == 0) {
  21. n = Integer.parseInt(line);
  22. } else {
  23. if (couleurs.containsKey(line)) {
  24. couleurs.put(line, couleurs.get(line)+1);
  25. } else {
  26. couleurs.put(line, 1);
  27. }
  28. }
  29. }
  30.  
  31. int max1 = 0, max2 = 0;
  32. String m1 = "", m2 = "";
  33. for (Map.Entry<String, Integer> pair: couleurs.entrySet()) {
  34. int c = pair.getValue();
  35.  
  36. if (c > max1) {
  37. if (max1 > max2) {
  38. max2 = max1;
  39. m2 = m1;
  40. }
  41.  
  42. max1 = c;
  43. m1 = pair.getKey();
  44. } else if (c > max2) {
  45. max2 = c;
  46. m2 = pair.getKey();
  47. }
  48. }
  49.  
  50. System.out.println(m1 + " " + m2);
  51.  
  52.  
  53. /* Vous pouvez aussi effectuer votre traitement une fois que vous avez lu toutes les données.*/
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement