Last active
December 3, 2015 11:51
-
-
Save ProZhar/3d1b443e1aa2a574b43b to your computer and use it in GitHub Desktop.
com.javarush.test.level08.lesson11.bonus02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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