Skip to content

Instantly share code, notes, and snippets.

@SwipeX
Created May 7, 2015 05:21

Revisions

  1. SwipeX created this gist May 7, 2015.
    42 changes: 42 additions & 0 deletions Application.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;

    /**
    * @author Tim Dekker
    * @since 5/7/15
    */
    public class Application {

    static HashMap<Rectangle, Integer> depth = new HashMap<Rectangle, Integer>();

    public static void main(String[] args) throws FileNotFoundException {
    Scanner scanner = new Scanner(new FileInputStream(new File("./src/test")));
    int count = Integer.parseInt(scanner.nextLine());
    for (int i = 0; i < count; i++) {
    String line = scanner.nextLine();
    String[] data = line.split(",");
    Rectangle rectangle = new Rectangle(data[0], data[1], data[2], data[3]);
    processRectangle(rectangle);
    }
    int max = -1;
    for (Map.Entry<Rectangle, Integer> entry : depth.entrySet()) {
    int temp = entry.getValue();
    if (temp > max)
    max = temp;
    }
    System.out.println(max);
    }

    private static void processRectangle(Rectangle rectangle) {
    for (Rectangle r : depth.keySet()) {
    if (r.contains(rectangle) || rectangle.contains(r)) {
    depth.put(r, depth.get(r) + 1);
    }
    }
    depth.put(rectangle, 0);
    }
    }