SymmetryDetection
SRM 713 · 2017-02-20 · by cgy4ever
Problem Statement
The board is called horizontally symmetric if it remains the same when flipped around a horizontal line that goes through the center of the board. If n is odd, this line goes through the middle of row (n-1)/2. If n is even, the line goes between rows (n/2)-1 and (n/2).
Similarly, the board is called vertically symmetric if it remains the same when flipped around a vertical line that goes through the center of the board.
Please help Ciel determine the types of symmetry of her board. Return one of the following four
- "Both" if Ciel's board is both horizontally and vertically symmetric.
- "Horizontally symmetric" if Ciel's board is horizontally symmetric but not vertically symmetric.
- "Vertically symmetric" if Ciel's board is vertically symmetric but not horizontally symmetric.
- "Neither" otherwise.
Notes
- The values n and m are not given explicitly. Instead, you can determine n as the number of elements in board and m as the length of any element in board.
Constraints
- n, m will be between 1 and 50, inclusive.
- board will contain exactly n elements.
- Each element in board will have exactly m characters.
- Each character in board will be '#' or '.'.
Statement by TopCoder, Inc. — view the original on the archive.
{"#####",
".###.",
"..#.."}
Returns: "Vertically symmetric"
If we flip this board according to the vertical line that goes through the middle of column 2, we will get exactly the same board. On the other hand, if we flip it according to the horizontal line that goes through the middle of row 1, we will get the following shape: ..#.. .###. ##### This is not the same board, which means that this board isn't horizontally symmetric.
{"#####",
"#...#",
"#####"}
Returns: "Both"
This time it is both horizontally and vertically symmetric.
{"#..",
"#..",
"#.."}
Returns: "Horizontally symmetric"
{"#.",
".#"}
Returns: "Neither"
{"#######",
"#..#..#",
"#######",
"...#...",
"#######"}
Returns: "Vertically symmetric"
Submissions are judged against all 82 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SymmetryDetection with a public method string detect(vector<string> board) · 82 test cases · 2 s / 256 MB per case