Skip to content

Instantly share code, notes, and snippets.

@ProZhar
Last active December 3, 2015 11:51
Show Gist options
  • Save ProZhar/3d1b443e1aa2a574b43b to your computer and use it in GitHub Desktop.
Save ProZhar/3d1b443e1aa2a574b43b to your computer and use it in GitHub Desktop.
com.javarush.test.level08.lesson11.bonus02
package com.javarush.test.level08.lesson11.bonus02;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/* Нужно добавить в программу новую функциональность
Задача: Программа определяет, какая семья (фамилию) живёт в доме с указанным номером.
Новая задача: Программа должна работать не с номерами домов, а с городами:
Пример ввода:
Москва
Ивановы
Киев
Петровы
Лондон
Абрамовичи
Лондон
Пример вывода:
Абрамовичи
*/
public class Solution
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//list of addresses
Map<String, String> addresses = new HashMap<>();
while (true)
{
String city = reader.readLine();
if (city.isEmpty()) break;
String family = reader.readLine();
if (family.isEmpty()) break; // чтобы не заносить город с пустой фамилией
addresses.put(city, family);
}
//read city
String city = reader.readLine();
if (!city.isEmpty()) // при пустом вводе ничего не выводим
{
String familySecondName = addresses.get(city);
System.out.println(familySecondName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment