Advertisement
savovaap_

Football

May 24th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class Football {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         TreeMap<String, Integer> statistic = new TreeMap<String, Integer>();
  10.  
  11.         String command = scanner.nextLine();
  12.         while(!command.equals("End of season")){
  13.             String name = command.split(" - ")[0];
  14.             String goals = command.split(" - ")[1];
  15.             if(statistic.containsKey(name)){
  16.                 statistic.put(name, statistic.get(name) + Integer.parseInt(goals));
  17.             }
  18.             else
  19.             {
  20.                 statistic.put(name, Integer.parseInt(goals));
  21.             }
  22.             command = scanner.nextLine();
  23.         }
  24.  
  25.         for (Map.Entry<String,Integer> entry: statistic.entrySet()) {
  26.             System.out.println(entry.getKey() + " -> " + entry.getValue());
  27.         }
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement