Problem:
Given two points, find the symmetric point (C is symmetric point of A and B, if B is mid point of A and C)
Input Format:
first line, T, contains number of test cases
T lines contains coordinates of 2 points A and B
Output Format:
Each line, containing symmetric point of A and B
Each line, containing symmetric point of A and B
Constraints:
none
none
Sample Input
2
0 0 2 2
1 1 3 3
0 0 2 2
1 1 3 3
Sample Output:
4 4
5 5
4 4
5 5
Explanations:
for first test case, 2,2 is midpoint of 4,4 and 0,0
for first test case, 2,2 is midpoint of 4,4 and 0,0
Solution:
chomp($t=<STDIN>);
for($i=0;$i<$t;$i++)
{
chomp($c=<STDIN>);
@arr=split(" ",$c);
$a=(2*$arr[2])-$arr[0];
$b=(2*$arr[3])-$arr[1];
push(@out,$a);
push(@out,$b);
}
$len=@out;
for($j=0;$j<$len;$j++)
{
print "$out[$j] $out[$j+1]\n";
$j++;
}
Tips:
Simple, C= 2B-1
No comments:
Post a Comment