import java.util.Scanner; import java.io.File; import java.io.PrintStream; import java.io.FileNotFoundException; /** * Solution to Skyline problem. * @author Dave Reed */ public class Skyline { public static void main(String[] args) throws FileNotFoundException { Scanner infile = new Scanner(new File("input1.txt")); PrintStream outfile = new PrintStream("output1.txt"); int[] skyline = new int[10001]; for (int i = 0; i < skyline.length; i++) { skyline[i] = 0; } while (infile.hasNextInt()) { int left = infile.nextInt(); int height = infile.nextInt(); int right = infile.nextInt(); for (int bldg = left; bldg < right; bldg++) { if (height > skyline[bldg]) { skyline[bldg] = height; } } } boolean first = true; for (int i = 0; i < 10000; i++) { if (skyline[i] != skyline[i+1]) { if (first) { first = false; } else { outfile.print(" "); } outfile.print((i+1) + " " + skyline[i+1]); } } outfile.println(); } }