304. Set Matrix Zeroes
MediumMatrix
If an element is 0, set its entire row and column to 0. Print the resulting matrix.
Input format
Line 1: r c Next r lines: c integers
Output format
The modified matrix.
Example 1
Input
3 3 1 1 1 1 0 1 1 1 1
Output
1 0 1 0 0 0 1 0 1
Example 2
Input
3 4 0 1 2 0 3 4 5 2 1 3 1 5
Output
0 0 0 0 0 4 5 0 0 3 1 0
Constraints
1 ≤ r, c ≤ 200
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…