Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- Map<String, List<Integer>> devices = new HashMap<>();
- Scanner sc = new Scanner(System.in);
- int maxDeviceCount = 0;
- for (int i = 0; i < 6; i++) {
- sc.nextLine();
- String device = sc.nextLine();
- List<Integer> prices = devices.get(device);
- if (prices == null) {
- prices = new ArrayList<>();
- devices.put(device, prices);
- }
- prices.add(Integer.valueOf(sc.nextLine()));
- if (prices.size() > maxDeviceCount) {
- maxDeviceCount = prices.size();
- }
- }
- String minDevice = null;
- int minPrice = Integer.MAX_VALUE;
- for (Map.Entry<String, List<Integer>> e : devices.entrySet()) {
- List<Integer> prices = e.getValue();
- if (prices.size() == maxDeviceCount) {
- Collections.sort(prices);
- if (!prices.isEmpty()) {
- int price = prices.get(0);
- if (price < minPrice) {
- minPrice = price;
- minDevice = e.getKey();
- }
- }
- }
- }
- System.out.print(minDevice);
- }
- }
Add Comment
Please, Sign In to add comment