Advertisement
liwgfr

Untitled

Mar 23rd, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. package binocla;
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.*;
  6.  
  7. public class Solution {
  8.     public static void main(String[] args) throws ParseException {
  9.         Scanner in = new Scanner(System.in);
  10.         String s = ""; // Для ввода данных
  11.  
  12.         HashMap<Date, Integer> customerProperties;
  13.         HashMap<String, HashMap<Date, Integer>> customer = new HashMap<>();
  14.  
  15.         HashMap<String, Integer> itemProperties;
  16.         HashMap<String, HashMap<String, Integer>> item = new HashMap<>();
  17.  
  18.         HashMap<String, String> shopProperties;
  19.         HashMap<String, HashMap<String, String>> shop = new HashMap<>();
  20.  
  21.         HashMap<Date, String> buyProperties;
  22.         HashMap<String, HashMap<Date, String>> buySettings = new HashMap<>();
  23.         HashMap<String, HashMap<String, HashMap<Date, String>>> buy = new HashMap<>();
  24.  
  25.  
  26.  
  27.         while (!s.contains("$")) { // До тех пор, пока строка не содержит $
  28.             s = in.nextLine();
  29.             String[] v = s.split(" ");
  30.             if (v[0].equals("c")) {
  31.                 customerProperties = customer.get(v[1]);
  32.                 if (customerProperties == null) {
  33.                     customerProperties = new HashMap<>();
  34.                 }
  35.                 customerProperties.put(new SimpleDateFormat("yyyy-mm-dd").parse(v[2]), Integer.parseInt(v[3]));
  36.                 customer.put(v[1], (HashMap<Date, Integer>) customerProperties.clone());
  37.             }
  38.             if (v[0].equals("i")) {
  39.                 itemProperties = item.get(v[1]);
  40.                 if (itemProperties == null) {
  41.                     itemProperties = new HashMap<>();
  42.                 }
  43.                 itemProperties.put(v[2], Integer.parseInt(v[3]));
  44.                 item.put(v[1], (HashMap<String, Integer>) itemProperties.clone());
  45.             }
  46.             if (v[0].equals("s")) {
  47.                 shopProperties = shop.get(v[1]);
  48.                 if (shopProperties == null) {
  49.                     shopProperties = new HashMap<>();
  50.                 }
  51.                 shopProperties.put(v[2], v[3]);
  52.                 shop.put(v[1], (HashMap<String, String>) shopProperties.clone());
  53.             }
  54.             if (v[0].equals("b")) {
  55.                 buyProperties = buySettings.get(v[3]);
  56.                 if (buyProperties == null) {
  57.                     buyProperties = new HashMap<>();
  58.                 }
  59.                 buySettings = buy.get(v[2]);
  60.                 if (buySettings == null) {
  61.                     buySettings = new HashMap<>();
  62.                 }
  63.                 buyProperties.put(new SimpleDateFormat("yyyy-mm-dd").parse(v[1]), v[3]);
  64.                 buySettings.put(v[4], (HashMap<Date, String>) buyProperties.clone());
  65.                 buy.put(v[2], (HashMap<String, HashMap<Date, String>>) buySettings.clone());
  66.             }
  67.         }
  68.         // System.out.println(customer);
  69.         // System.out.println(item);
  70.         ArrayList<String> ar = new ArrayList<>();
  71.         for (Map.Entry<String, HashMap<String, Integer>> z: item.entrySet()) {
  72.             ar.add(z.getValue().keySet().toArray()[0].toString());
  73.         }
  74.         Set<String> set = new HashSet<>(ar);
  75.         if (ar.size() != set.size()) {
  76.             System.out.println("YES");
  77.         } else {
  78.             System.out.println("NO");
  79.         }
  80.         // System.out.println(shop);
  81.         // System.out.println(buy);
  82.  
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement