Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Total {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- Map<Calendar, Integer> total_of_day = new TreeMap<Calendar, Integer>();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- while (in.hasNextLine()) {
- String[] c1 = in.nextLine().split(",");
- Calendar c = GregorianCalendar.getInstance();
- try {
- c.setTime(format.parse(c1[0]));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- String[] c2 = c1[1].split(":");
- int amount = new Integer(c2[1]);
- if (total_of_day.get(c) == null) {
- total_of_day.put(c, 0);
- }
- total_of_day.put(c, total_of_day.get(c) + amount);
- }
- in.close();
- for (Entry<Calendar, Integer> e : total_of_day.entrySet()) {
- System.out.format("%tY-%tm-%td\t%d\n", e.getKey(), e.getKey(), e.getKey(), e.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement