// java State < ST_LOW48.BNA
// ST_02 is Alaska (careful with -180 and +180 longitude)

import java.awt.Color;


public class US {

    public static String[] readCodes() {
        int N = 57;
        String[] states = new String[N];
        In in = new In("codes.txt");
        in.readLine();
        while (!in.isEmpty()) {
            String line = in.readLine();
            String[] fields = line.split("\\t+");
            String name = fields[0];
            int fips = Integer.parseInt(fields[2]);
            states[fips] = name;
        }
        return states;
    }

    public static void main(String[] args) {
        String[] states = readCodes();
        for (int i = 0; i < states.length; i++)
            System.out.println(i + "\t" + states[i]);

        double xmin = -124.731;
        double xmax =  -66.980;
        double ymin =   24.544;
        double ymax =   49.384;

       
        int HEIGHT = 800;
        double ratio = 0.6;  // a hack
        int WIDTH = (int) (HEIGHT / ratio);
        StdDraw.create(WIDTH, HEIGHT);
        StdDraw.setScale(xmin - 1, ymin - 1, xmax + 1, ymax + 1);

        // StdDraw.setColor(StdDraw.BLUE);
        StdDraw.fillOff();
        while (!StdIn.isEmpty()) {
            // StdDraw.setColorRandom();
            String line = StdIn.readLine();
            System.out.println(line);
            String[] fields = line.split(",");
            int fips = Integer.parseInt(fields[0].replaceAll("\"", ""));
            System.out.println("state = " + states[fips]);
            int N = Integer.parseInt(fields[3]);
            Point p0 = new Point(StdIn.readDouble(), StdIn.readDouble());
            Polygon poly = new Polygon();
            poly.add(p0);

            for (int i = 1; i < N - 1; i++)  {
               Point p = new Point(StdIn.readDouble(), StdIn.readDouble());
               if (p.eq(p0)) {          // separate polygon
                   poly.draw();
                   poly = new Polygon();
                   p = new Point(StdIn.readDouble(), StdIn.readDouble());
                   i++;
               }
               poly.add(p);
            }
            poly.draw();

            StdIn.readLine();  // ignore last point - it is same as first
            StdIn.readLine();  // eat up rest of whitespace on current line
            StdDraw.show();
        }
    }
}

