Advertisement
Guest User

Untitled

a guest
May 28th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication13;
  7.  
  8.  
  9. import java.io.BufferedReader;
  10. import java.io.IOException;
  11. import java.io.InputStreamReader;
  12. import java.util.*;
  13. import java.util.stream.Collectors;
  14.  
  15. public class JavaApplication13 {
  16.     public static void main(String[] args) throws IOException {
  17.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  18.  
  19.         String input = bf.readLine();
  20.  
  21.         LinkedHashMap<String,LinkedHashMap<String, Integer>> map = new LinkedHashMap<>();
  22.         map.put("Arrow",new LinkedHashMap<>());
  23.         map.put("Flame",new LinkedHashMap<>());
  24.         map.put("Hydra",new LinkedHashMap<>());
  25.         map.put("Orchid",new LinkedHashMap<>());
  26.         map.put("Pearl",new LinkedHashMap<>());
  27.  
  28.         while (!input.equals("Recruit")) {
  29.             String[] tokens = input.split(":");
  30.             String name = tokens[0];
  31.             int number = Integer.parseInt(tokens[1]);
  32.             String station = tokens[2];
  33.             if (map.containsKey(station)){
  34.                 map.get(station).put(name,number);
  35.             }
  36.  
  37.             input = bf.readLine();
  38.         }
  39.         String command = bf.readLine();
  40.         if (command.equals("DHARMA Initiative")){
  41.             map.entrySet()
  42.                     .stream()
  43.                     .sorted((a1,a2) -> Integer.compare(a2.getValue().size(),a1.getValue().size()))
  44.                     .forEach(a -> {
  45.                          System.out.println("The " + a.getKey() + " has " + a.getValue().size() + " DHARMA recruits in it.");
  46.                     });
  47.         } else if (map.keySet().contains(command)){
  48.             if (command.equals("Arrow")){
  49.                 System.out.println("The Arrow station: Development of defensive strategies, and Intelligence gathering.");
  50.             } else if (command.equals("Flame")){
  51.                 System.out.println("The Flame station: Communication.");
  52.             } else if (command.equals("Hydra")){
  53.                 System.out.println("The Hydra station: Zoological Research.");
  54.             }else if (command.equals("Orchid")){
  55.                 System.out.println("The Orchid station: Space-time manipulation research, disguised as a Botanical station.");
  56.             }else if (command.equals("Pearl")){
  57.                 System.out.println("The Pearl station: Psychological Research and/or Observation.");
  58.             }
  59.             Map<String, Integer> result =  map.get(command).entrySet().stream()
  60.                     .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
  61.                     .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
  62.                             (oldValue, newValue) -> oldValue, LinkedHashMap::new));
  63.            
  64.             if(result.isEmpty()){
  65.                 System.out.println("No recruits.");
  66.             }else{
  67.                 result.forEach((k, v)->{
  68.                     System.out.println("###" + k + " - " + v);
  69.                 });
  70.             }
  71.         } else  {
  72.             System.out.println("DHARMA Initiative does not have such a station!");
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement