My code below works if I compile it on online perl compiler.
But it does not work on Hackerrank.
I am pretty sure it is related with the input/output format, which I do not know how to fix.
In my code, I assume the input is just a list of integer.
I have read about other problems related with stdin/out in this forum, but since i am a beginner, I cannot understand the discussion.
Problem : findPoint
sub findPoint {
# Write your code here
# my ($n, $px, $py, $qx, $qy) = @_;
my $m = scalar(@_);
my $px = 0;
my $py = 0;
my $qx = 0;
my $qy = 0;
my $rx = 0;
my $ry = 0;
for (my $i = 0; $i < $_[0]; $i++){
$px = $_[$i*4 + 1];
$py = $_[$i*4 + 2];
$qx = $_[$i*4 + 3];
$qy = $_[$i*4 + 4];
$rx = 2*$qx - $px;
$ry = 2*$qy - $py;
print "$rx $ry n";
}
}
findPoint( 2, 0, 0, 1, 1, 1, 1, 2, 2)
format from Hackerrank.
enter image description here
enter image description here
I tried to compile it on online perl compiler and it works.
occasional is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.