输入:第一行四个浮点数,分别是起始顶点和对角顶点的坐标x1 y1 x2 y2。然后是不定个数的变换,每个变换一行,每行第一个数据是字符,'T’表示平移,'S’表示对称。如果是平移,后面的数据为两个整数,分别表示X方向和Y方向的平移量;如果是对称,后面是一个整数:0表示以原点为参照求对称点,1 表示以X轴为参照求对称点,2表示以Y轴为参照求对称点。数据中间用空格分隔。所有数据均为整数。
参见样例:
输入:
1 2 4 6
T 2 3
S 1
S 2
S 0
T 4 5
输出:
(7,10)(10,14) 12
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
float x1, x2, y1, y2;
x1 = in.nextFloat();
y1 = in.nextFloat();
x2 = in.nextFloat();
y2 = in.nextFloat();
char m;
Rectangle A = new Rectangle(x1, x2, y1, y2);
Point p1 = new Point(x1, y1);
Point p2 = new Point(x2, y2);
while (in.hasNext()) {
m = in.next().charAt(0);
if (m == 'T') {
float a, b;
a = in.nextFloat();
b = in.nextFloat();
p1.move(a, b);
p2.move(a, b);
}
if (m == 'S') {
int c;
c = in.nextInt();
if (c == 0) {
A.change0(x1, x2, y1, y2);
}
if (c == 1) {
A.change1(y1, y2);
}
if (c == 2) {
A.change2(x1, x2);
}
}
}
p1.shuchu();
p2.shuchu();
A.area();
}
}
class Point {
private float x, y;
public Point(float x, float y) {
this.x = x;
this.y = y;
}
public Point(Point p) {
x = p.x;
y = p.y;
}
public void move(float a, float b) {
x += a;
y += b;
}
public void shuchu() {
System.out.printf("(%.0f,%.0f)", x, y);
}
}
class Rectangle {
private float x1, x2, y1, y2;
private Point p1, p2;
public Rectangle(float x1, float x2, float y1, float y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
p1 = new Point(x1, y1);
p2 = new Point(x2, y2);
}
public void change0(float x1, float x2, float y1, float y2) {
x1 = -x1;
x2 = -x2;
y1 = -y1;
y2 = -y2;
}
public void change1(float y1, float y2) {
y1 = -y1;
y2 = -y2;
}
public void change2(float x1, float x2) {
x1 = -x1;
x2 = -x2;
}
public void area() {
System.out.print(" " + (int) (x2 - x1) * (int) (y2 - y1));
}
}