/* vim: set sw=4 sts=4 et foldmethod=syntax : */ import java.util.*; import java.io.*; public class BusyGraph { public static void main(String[] args) throws IOException { if (1 != args.length) { System.out.println("Usage: java BusyGraph problemDirectory"); System.exit(1); } File dir = new File(new File(args[0]), "output"); long startTime = Long.MAX_VALUE, stopTime = -1; Map startTimes = new HashMap(); Map stopTimes = new HashMap(); for (String f : dir.list()) { if (f.endsWith(".start")) { Scanner sc = new Scanner(new File(dir, f)); long thisStartTime = sc.nextLong(); startTimes.put(f.substring(0, f.lastIndexOf('.')), thisStartTime); startTime = Math.min(startTime, thisStartTime); sc.close(); } else if (f.endsWith(".stop")) { Scanner sc = new Scanner(new File(dir, f)); long thisStopTime = sc.nextLong(); stopTimes.put(f.substring(0, f.lastIndexOf('.')), thisStopTime); stopTime = Math.max(stopTime, thisStopTime); sc.close(); } } if (0 == startTimes.size()) { System.out.println("Found no start times"); System.exit(1); } else if (startTimes.size() != stopTimes.size()) { System.out.println("Found " + startTimes.size() + " start times but " + stopTimes.size() + " stop times"); System.exit(1); } for (long t = startTime ; t <= stopTime + 1 ; ++t) { int c = 0; for (String s : startTimes.keySet()) { if (t >= startTimes.get(s) && t <= stopTimes.get(s)) ++c; } System.out.printf("%d %d\n", t - startTime, c); } } }