UVA – 477 – Points in Figures: Rectangles And Circles

import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Shape> shapes = new ArrayList<Shape>();
		String line;
		while (!(line = in.readLine()).equals("*")) {
			String[] tokens = line.split(" ");
			double x = Double.parseDouble(tokens[1]), y = Double.parseDouble(tokens[2]);
			if (tokens[0].equals("c")) {
				double radius = Double.parseDouble(tokens[3]);
				shapes.add(new Ellipse2D.Double(x - radius, y - radius, 2 * radius, 2 * radius));
			if (tokens[0].equals("r")) {

				double w = Math.abs(Double.parseDouble(tokens[3]) - x);
				double h = Math.abs(y- Double.parseDouble(tokens[4]));
				y= y-h;
				shapes.add(new Rectangle2D.Double(x, y, w, h));
		int point=0;
		while(!(line = in.readLine()).equals("9999.9 9999.9")){
			String[] tokens = line.split(" ");
			double x = Double.parseDouble(tokens[0]), y = Double.parseDouble(tokens[1]);
			Point2D.Double p= new Point2D.Double(x, y);
			boolean found=false;
			for(int shape=0; shape<shapes.size(); shape++){

					System.out.printf("Point %d is contained in figure %d\n", point, shape+1);
					found= true;
				System.out.printf("Point %d is not contained in any figure\n", point);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: