Advertisement
cd62131

Total

Jul 28th, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.15 KB | None | 0 0
  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.GregorianCalendar;
  5. import java.util.Map;
  6. import java.util.Map.Entry;
  7. import java.util.Scanner;
  8. import java.util.TreeMap;
  9.  
  10. public class Total {
  11.   public static void main(String[] args) {
  12.     Scanner in = new Scanner(System.in);
  13.     Map<Calendar, Integer> total_of_day = new TreeMap<Calendar, Integer>();
  14.     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  15.     while (in.hasNextLine()) {
  16.       String[] c1 = in.nextLine().split(",");
  17.       Calendar c = GregorianCalendar.getInstance();
  18.       try {
  19.         c.setTime(format.parse(c1[0]));
  20.       } catch (ParseException e) {
  21.         e.printStackTrace();
  22.       }
  23.       String[] c2 = c1[1].split(":");
  24.       int amount = new Integer(c2[1]);
  25.       if (total_of_day.get(c) == null) {
  26.         total_of_day.put(c, 0);
  27.       }
  28.       total_of_day.put(c, total_of_day.get(c) + amount);
  29.     }
  30.     in.close();
  31.     for (Entry<Calendar, Integer> e : total_of_day.entrySet()) {
  32.       System.out.format("%tY-%tm-%td\t%d\n", e.getKey(), e.getKey(), e.getKey(), e.getValue());
  33.     }
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement