Ввод:
Jameson
Johnson
Green
London
Smith
Brown
Black
Washington
Вывод
London
[Jameson, Johnson, Green]
Вроде как все ок, же, нет? Но валидатор не пропускает
package com.javarush.task.task08.task0829;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/*
Модернизация ПО
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// List families by City
HashMap<String, ArrayList<String>> familiesByCityName = new HashMap<>();
while (true) {
ArrayList<String> families = new ArrayList<>();
boolean isEndOfTheCycle = false;
String cityName = null;
while (true) {
if(isEndOfTheCycle)
{
families = new ArrayList<>();
break;
}
String family = reader.readLine();
if (family.isEmpty()) {
cityName = reader.readLine();
if(!cityName.isEmpty()){
familiesByCityName.put(cityName, families);
}
isEndOfTheCycle = true;
continue;
}
families.add(family);
}
if(cityName.isEmpty()) break;
}
// Read the cityName
String cityName = reader.readLine();
if (familiesByCityName.size() !=0 && familiesByCityName.containsKey(cityName)) {
ArrayList result = familiesByCityName.get(cityName);
System.out.println(result);
}
}
}