Advertisement
Rosamonaar

Max in row and column

Oct 3rd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main extends A{
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int [][] data = new int[1000][1000];
  8.         int [] maxInRow = new int[1000];
  9.         int [] maxInColumn = new int[1000];
  10.         int [] countOfSymbols = new int[1000];
  11.  
  12.         int i = 0;
  13.         for (; scanner.hasNext(); i++) {
  14.             String tmp = scanner.nextLine();
  15.             Scanner sc = new Scanner(tmp);
  16.             for (int j = 0; sc.hasNext(); j++) {
  17.                 data[i][j] = sc.nextInt();
  18.                 countOfSymbols[i]++;
  19.                 if (maxInRow[i] < data[i][j]) {
  20.                     maxInRow[i] = data[i][j];
  21.                 }
  22.                 if (maxInColumn[j] < data[i][j]) {
  23.                     maxInColumn[j] = data[i][j];
  24.                 }
  25.             }
  26.         }
  27.  
  28.         for(int j = 0; j <= i; j++) {
  29.             for(int k = 0; k < countOfSymbols[j]; k++) {
  30.                 System.out.print(Math.max(maxInRow[j], maxInColumn[k]) + " ");
  31.             }
  32.             System.out.println();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement