Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- /**
- * Created by Zdravko on 5/30/2016.
- */
- public class PopulationCounter {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- HashMap<String, HashMap<String, Integer>> countries = new HashMap<String,HashMap<String,Integer>>();
- String commands = scan.nextLine();
- while (!commands.equals("report")) {
- String[] input = commands.split("\\|");
- String city = input[0];
- String country = input[1];
- int population = Integer.parseInt(input[2]);
- if(!countries.containsKey(country)){
- countries.put(country, new LinkedHashMap<String,Integer>());
- }
- if(!countries.get(country).containsKey(city)){
- countries.get(country).put(city, 0);
- }
- int sum = countries.get(country).get(city) + population;
- countries.get(country).put(city,sum);
- commands = scan.nextLine();
- }
- commands = scan.nextLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement