import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; /** * */ /** * Display program for viewing the input data to FindPoly * * @author zeil * */ public class FindPolyValidate { public class LineSegment { public Point p1; public Point p2; public LineSegment (Point p1, Point p2) { this.p1 = p1; this.p2 = p2; } } ArrayList lineSegments; public FindPolyValidate() { } final void fail(String msg, int lineCounter, int code) { System.err.println(msg + " at line " + lineCounter); System.exit(code); } final void solve () throws IOException { BufferedReader bin = new BufferedReader(new InputStreamReader(System.in)); lineSegments = new ArrayList<>(); String line = bin.readLine(); HashSet priors = new HashSet<>(); int lineCounter = 0; while (line != null) { String[] segmentParts = line.split(";"); for (String segmentStr: segmentParts) { if (segmentStr.length() > 0) { segmentStr = segmentStr.replaceAll("[(,)]", " "); Scanner in = new Scanner(segmentStr); int x1 = in.nextInt(); int y1 = in.nextInt(); int x2 = in.nextInt(); int y2 = in.nextInt(); lineSegments.add(new LineSegment(new Point(x1,y1), new Point(x2,y2))); in.close(); if (x1 < 0 || x1 > 99) fail ("x1 out of bounds", lineCounter, 1); if (y1 < 0 || y1 > 99) fail ("y1 out of bounds", lineCounter, 1); if (x2 < 0 || x2 > 99) fail ("x2 out of bounds", lineCounter, 1); if (y2 < 0 || y2 > 99) fail ("y2 out of bounds", lineCounter, 1); if (x1 == x2 && y1 == y2) fail ("zero length segment", lineCounter, 2); String key = "" + x1 + ":" + y1 + "," + x2 + ":" + y2; if (priors.contains(key)) fail ("duplicate segment", lineCounter, 3); priors.add(key); key = "" + x2 + ":" + y2 + "," + x1 + ":" + y1; if (priors.contains(key)) fail ("duplicate (mirrored) segment", lineCounter, 3); priors.add(key); } } line = bin.readLine(); ++lineCounter; } if (priors.size() > 400) { fail ("Too many line segments: " + priors.size(), 999, 4); } } /** * @param args * @throws IOException */ public static void main (String[] argv) throws IOException { new FindPolyValidate().solve (); System.exit(42); } }