Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package binocla;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- public class Solution {
- public static void main(String[] args) throws ParseException {
- Scanner in = new Scanner(System.in);
- String s = ""; // Для ввода данных
- HashMap<Date, Integer> customerProperties;
- HashMap<String, HashMap<Date, Integer>> customer = new HashMap<>();
- HashMap<String, Integer> itemProperties;
- HashMap<String, HashMap<String, Integer>> item = new HashMap<>();
- HashMap<String, String> shopProperties;
- HashMap<String, HashMap<String, String>> shop = new HashMap<>();
- HashMap<Date, String> buyProperties;
- HashMap<String, HashMap<Date, String>> buySettings = new HashMap<>();
- HashMap<String, HashMap<String, HashMap<Date, String>>> buy = new HashMap<>();
- while (!s.contains("$")) { // До тех пор, пока строка не содержит $
- s = in.nextLine();
- String[] v = s.split(" ");
- if (v[0].equals("c")) {
- customerProperties = customer.get(v[1]);
- if (customerProperties == null) {
- customerProperties = new HashMap<>();
- }
- customerProperties.put(new SimpleDateFormat("yyyy-mm-dd").parse(v[2]), Integer.parseInt(v[3]));
- customer.put(v[1], (HashMap<Date, Integer>) customerProperties.clone());
- }
- if (v[0].equals("i")) {
- itemProperties = item.get(v[1]);
- if (itemProperties == null) {
- itemProperties = new HashMap<>();
- }
- itemProperties.put(v[2], Integer.parseInt(v[3]));
- item.put(v[1], (HashMap<String, Integer>) itemProperties.clone());
- }
- if (v[0].equals("s")) {
- shopProperties = shop.get(v[1]);
- if (shopProperties == null) {
- shopProperties = new HashMap<>();
- }
- shopProperties.put(v[2], v[3]);
- shop.put(v[1], (HashMap<String, String>) shopProperties.clone());
- }
- if (v[0].equals("b")) {
- buyProperties = buySettings.get(v[3]);
- if (buyProperties == null) {
- buyProperties = new HashMap<>();
- }
- buySettings = buy.get(v[2]);
- if (buySettings == null) {
- buySettings = new HashMap<>();
- }
- buyProperties.put(new SimpleDateFormat("yyyy-mm-dd").parse(v[1]), v[3]);
- buySettings.put(v[4], (HashMap<Date, String>) buyProperties.clone());
- buy.put(v[2], (HashMap<String, HashMap<Date, String>>) buySettings.clone());
- }
- }
- // System.out.println(customer);
- // System.out.println(item);
- if (buy.isEmpty()) {
- for (String name: customer.keySet()) {
- System.out.println(name + " " + 0);
- }
- }
- for (Map.Entry<String, HashMap<String, HashMap<Date, String>>> x: buy.entrySet()) {
- System.out.println(x.getKey() + " " + x.getValue().keySet().size());
- }
- // System.out.println(shop);
- // System.out.println(buy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement