Advertisement
Guest User

sport

a guest
Sep 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.HashMap;
  5.  
  6. public class SportHASH {
  7. public static void main(String[] args) throws IOException {
  8. HashMap<String,String> mapa = new HashMap<>();
  9. HashMap<String,Integer> mapasport = new HashMap<>();
  10. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11. int n = Integer.parseInt(br.readLine());
  12. int brojac = 0;
  13. String[] sports = new String[n];
  14.  
  15. for(int i =0;i<n;i++){
  16.  
  17. String[] e = br.readLine().split(" ");
  18.  
  19. if(!mapa.containsKey(e[0])){
  20.  
  21. mapa.put(e[0],e[1]);
  22.  
  23. if(mapasport.containsKey(e[1])){
  24.  
  25. brojac = mapasport.get(e[1]) + 1;
  26.  
  27. mapasport.put(e[1],brojac);
  28.  
  29. }else{
  30.  
  31. mapasport.put(e[1],1);
  32. }
  33. sports[i] = e[1];
  34. }
  35. }
  36. //System.out.println(mapasport);
  37. int max = 0;
  38.  
  39. String sport =null;
  40.  
  41. for(int i =0;i < mapasport.size();i++){
  42.  
  43. if(mapasport.containsKey(sports[i])){
  44.  
  45. int k = mapasport.get(sports[i]);
  46.  
  47. if(k > max){
  48.  
  49. max = k;
  50.  
  51. sport = sports[i];
  52.  
  53. }
  54. }
  55. }
  56.  
  57. int football = mapasport.get("football");
  58. System.out.println(sport);
  59. System.out.println(football);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement