Problem 989
Flipping an Image
Easy · 10 pts · Matrix, Two Pointers, Bit Manipulation
Problem
A binary image is given as a matrix of 0s and 1s. First flip it horizontally, which reverses every row, and then invert it, which turns every 0 into 1 and every 1 into 0. Print the resulting image. Both steps can be done in one pass per row: walk two pointers from the ends of the row towards the middle, swapping and inverting the two values as you go.
Input
The first line contains R and C. Each of the next R lines contains C integers. Every value is 0 or 1.
Output
Print the resulting matrix, one row per line.
Constraints
1 <= R, C <= 20
Example input
3 3 1 1 0 1 0 1 0 0 0
Example output
1 0 0 0 1 0 1 1 1
Explanation
The row 1 1 0 reversed is 0 1 1, and inverted becomes 1 0 0. Doing this for 1 1 0 / 1 0 1 / 0 0 0 gives 1 0 0 / 0 1 0 / 1 1 1.