Problem:
Given a NxN Matrix(N is odd). Each block contains a letter from A-Z. Find whether matrix is symmetric with respect to central block. Central block for 3x3 matrix is (1,1), index starting from 0.
Input Format:
N
Next N lines containing content of each row.
Next N lines containing content of each row.
Output Format:
YES/NO- whether matrix is symetric or notConstraints:
N is always oddSample Input
5
ABFWW
TTTOP
ASDSA
POTTT
WWFBA
ABFWW
TTTOP
ASDSA
POTTT
WWFBA
Sample Output:
YESExplanations:
It is symmetric wrt to D(2,2) , example (0,0)=(4,4)=A
Solution:
$str;
for($i=0;$i<$n;$i++)
{
chomp($tmp=<STDIN>);
$str=$str.$tmp;
}
if($str eq reverse($str))
{
print "YES";
}
else
{
print "NO";
}
Tips:
No need to make N arrays and then compare, use string
I couldn't refrain from commenting. Exceptionally well written!
ReplyDeleteAlso visit my blog; CT limo