Sator Square
InterviewTime limit1sMemory limit256 MB
Given an N by N grid of letters, check whether it reads the same horizontally and vertically, printing YES or NO.
- Level
Easy2 of 10
- Topics
- Implementation, Array, String
- Solved
- No attempts yet
Problem
Have you ever heard of a Sator square? A Sator square is, simply put, "a set of words that reads the same horizontally and vertically." Some examples are shown below.
라팔아
팔렸니
아니오
호반우
반기는
우는나
Dribi, who loves to drink, dozed off in math class after drinking heavily the night before, got caught by the teacher, and was given homework: determine whether sets of words are Sator squares.
But checking by eye whether a large N × N set of words is a Sator square was not easy.
Poor Dribi cannot go home until the homework is finished. Given an N × N set of words, write a program that determines whether it is a Sator square.
Help Dribi!
Input
The first line gives the word length N. (2 ≤ N ≤ 100)
From the second line, N lines follow, each giving the words of one row of the set with no spaces. The words consist only of uppercase English letters.
Output
If the given set of words is a Sator square, print "YES"; otherwise print "NO". (Excluding the quotation marks.)