|
| 1 | +package Problem1; |
| 2 | + |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +public class Problem1_1 { |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + public static void markRow(int rowArr[], int row , int col){ |
| 10 | + rowArr[row] = 1; |
| 11 | + } |
| 12 | + public static void markCol(int colArr[] , int row , int col){ |
| 13 | + colArr[col] = 1; |
| 14 | + } |
| 15 | + |
| 16 | + public static void markRow(int arr[][] , int row){ |
| 17 | + for(int i = 0; i < arr.length; i++){ |
| 18 | + arr[i][row] = 0; |
| 19 | + } |
| 20 | + } |
| 21 | + public static void markCol(int arr[][] , int col){ |
| 22 | + for(int i = 0; i < arr[0].length; i++){ |
| 23 | + arr[col][i] = 0; |
| 24 | + } |
| 25 | + } |
| 26 | + public static int[][] fun(int arr[][] , int row[],int col[] , int n , int m){ |
| 27 | + |
| 28 | + for(int i = 0; i < n; i++){ |
| 29 | + for(int j = 0; j < m; j++){ |
| 30 | + if(arr[i][j] == 0){ |
| 31 | + markRow(row, i , j); |
| 32 | + markCol(col, i , j); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + for(int i = 0; i < n; i++){ |
| 38 | + if(row[i] == 1){ |
| 39 | + markRow(arr , i ); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + for(int i = 0; i < m; i++){ |
| 44 | + if(col[i] == 1){ |
| 45 | + markCol(arr , i ); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return arr; |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + public static void main(String[] args) { |
| 54 | + |
| 55 | + |
| 56 | + Scanner sc = new Scanner(System.in); |
| 57 | + |
| 58 | + int n = sc.nextInt(); |
| 59 | + int m = sc.nextInt(); |
| 60 | + |
| 61 | + |
| 62 | + int arr[][] = new int[n][m]; |
| 63 | + |
| 64 | + int row[] = new int[n]; |
| 65 | + int col[] = new int[m]; |
| 66 | + |
| 67 | + for(int i = 0; i < n; i++){ |
| 68 | + for(int j = 0; j < m; j++){ |
| 69 | + arr[i][j] = sc.nextInt(); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + int res[][] = fun(arr,row,col, n, m); |
| 74 | + |
| 75 | + for(int i = 0; i < n; i++){ |
| 76 | + for(int j = 0; j < m; j++){ |
| 77 | + System.out.print(arr[i][j] + " "); |
| 78 | + } |
| 79 | + System.out.println(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments