Advertisement
roronoa

trois sommes lignes, colonnes, tout

Sep 8th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution {
  5.  
  6.     public static void main(String args[]) {
  7.         Scanner in = new Scanner(System.in);
  8.         int n = in.nextInt();
  9.         int m = in.nextInt();
  10.         int[][] mat = new int[n][m];
  11.         for (int i = 0; i < n; i++) {
  12.             for (int j = 0; j < m; j++) {
  13.                 int read = in.nextInt();
  14.                 mat[i][j] = Math.abs(read);
  15.             }
  16.         }
  17.         int n1 = mat[0][0];
  18.         int nI = mat[0][0];
  19.         int x = mat[0][0];
  20.        
  21.         for (int i = 0; i < n; i++) {
  22.             int sum = 0;            
  23.             for (int j = 0; j < m; j++) {
  24.                 sum += mat[i][j];
  25.                 if(Math.abs(mat[i][j]) > x)
  26.                     x = Math.abs(mat[i][j]);
  27.             }
  28.             if(sum > n1)
  29.                 n1 = sum;
  30.         }
  31.         for (int i = 0; i < m; i++) {
  32.             int sum2 = 0;
  33.            
  34.             for (int j = 0; j < n; j++) {
  35.                 sum2 += mat[j][i];
  36.             }
  37.             if(sum2 > nI)
  38.                 nI = sum2;
  39.         }
  40.         System.out.println(nI + " " + n1 + " "+ x);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement