public class TimeSeries {

    public static void main(String[] args)throws IOException{
        int i=0;
        String startMonth ="";
        String endMonth = "";
        TreeMap<String,TreeMap<String,Integer>> map = new TreeMap<>(Collections.reverseOrder());
        String line ="";


           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while((line = br.readLine()) != null){
                if(i==0){
                    String []months = line.trim().split(",");
                    startMonth = months[0].trim();
                    endMonth = months[1].trim();
                    i++;
                }else if(i==1){i++;continue;}
                else{
                    String[] strings = line.trim().split(",");
                    String date = strings[0].trim();
                    date = date.substring(0,date.length()-3);
                    if(date.compareTo(startMonth)<0||date.compareTo(endMonth)>=0) continue;

                    String category = strings[1].trim();
                    int count = Integer.parseInt(strings[2].trim());
                    if(!map.containsKey(date)){
                        map.put(date,new TreeMap<String,Integer>());

                    }
                    TreeMap<String,Integer> treeMap = map.get(date);
                    if(!treeMap.containsKey(category)){
                        treeMap.put(category,count);
                    }
                    else{
                        treeMap.put(category,treeMap.get(category)+count);
                    }
                    i++;
                }

            }

        for(String date :map.keySet()){
                StringBuilder sb = new StringBuilder();
                sb.append(date);

                for(String category: map.get(date).keySet()){
                    sb.append(", ");
                    sb.append(category);
                    sb.append(", ");
                    sb.append(map.get(date).get(category));

                }
                System.out.println(sb.toString());

        }


    }
}

results matching ""

    No results matching ""