Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaProModule.JavaAdvanced.SetsAndMapsLab;
- import java.util.*;
- import java.util.stream.Collectors;
- public class CitiesByContinentAndCountry_06 {
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- Map<String,Map<String,List<String>>> data = new LinkedHashMap<>();
- // we have Continent,Country,City
- int loop = Integer.parseInt(read.nextLine());
- for (int index = 0; index < loop; index++) {
- String [] input = read.nextLine().split("\\s+");
- String continent = input[0];
- String country = input[1];
- String city = input[2];
- data.putIfAbsent(continent,new LinkedHashMap<>());
- data.get(continent).putIfAbsent(country,new ArrayList<>());
- data.get(continent).get(country).add(city);
- }
- data.forEach((key,value) -> {
- System.out.println(key + ":");
- value.forEach((innerKey,innerValue) -> {
- System.out.println(" " + innerKey + " -> " + String.join(", ",innerValue));
- });
- });
- /* for (Map.Entry<String, Map<String, List<String>>> entry : data.entrySet()) {
- String key = entry.getKey();
- Map<String, List<String>> value = entry.getValue();
- System.out.println(key + ":");
- value.forEach((innerKey, innerValue) -> {
- System.out.println(" " + innerKey + " -> " + String.join(", ", innerValue));
- });
- } for (Map.Entry<String, List<String>> entry : value.entrySet()) {
- String innerKey = entry.getKey();
- List<String> innerValue = entry.getValue();
- System.out.println(" " + innerKey + " -> " + String.join(", ", innerValue));
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement