Advertisement
16112

Курсова Работа 2 - 5.4б Футболен мач

Apr 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package testing;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6. import java.util.Scanner;
  7.  
  8. public class Pet_ChetiriB {
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner sc = new Scanner(System.in);
  12.         HashMap<String, Integer> goals = new HashMap<String, Integer>();
  13.  
  14.         while (true) {
  15.             String[] input = sc.nextLine().split(" - ");
  16.  
  17.             if (input[0].equalsIgnoreCase("end of season")) {
  18.                 break;
  19.             }
  20.             if (goals.containsKey(input[0])) {
  21.                 goals.put(input[0], goals.get(input[0]) + Integer.parseInt(input[1]));
  22.             } else {
  23.                 goals.put(input[0], Integer.parseInt(input[1]));
  24.             }
  25.         }
  26.         ArrayList<String> keys = new ArrayList<String>(goals.keySet());
  27.         Collections.sort(keys);
  28.  
  29.         for (String s : keys) {
  30.             System.out.println(s + " -> " + goals.get(s));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement