Java——Shift Dot(點的位移)
阿新 • • 發佈:2018-11-29
Shift Dot
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
給出平面直角座標系中的一點,並順序給出n個向量,求該點根據給定的n個向量位移後的位置。
Input
多組輸入,第一行是三個整數x,y,n,表示點的座標(x,y),和向量的個數n。接下來n行,每行兩個數xi,yi,表示第i個向量。題目中所有資料不會超出整形範圍。
Output
每組輸入輸出一行,"(x,y)"表示點的最終位置。
Sample Input
0 0 1
2 3
0 0 2
1 2
2 3
Sample Output
(2,3)
(3,5)
AC程式碼:
import java.util.Scanner; class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public Point move(int x, int y) { //每次輸入便更新一次電 this.x += x; this.y += y; return new Point(this.x, this.y); } } public class Main { public static void main(String[] args) { Scanner mi = new Scanner(System.in); while (mi.hasNext()) { Point p = new Point(mi.nextInt(), mi.nextInt()); int n = mi.nextInt(); for (int i = 0; i < n; i++) { p = p.move(mi.nextInt(), mi.nextInt()); } System.out.println("(" + p.x + "," + p.y + ")"); } mi.close(); } }
——————
餘生還請多多指教!