Advertisement
Josif_tepe

Untitled

Jan 8th, 2024
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(int argc, const char * argv[]) {
  5.     int n, m;
  6.     scanf("%d%d", &n, &m);
  7.     int mat[n][m];
  8.     for(int i = 0; i < n; i++) {
  9.         for(int j = 0; j < m; j++) {
  10.             scanf("%d", &mat[i][j]);
  11.         }
  12.     }
  13.     int maksimum = 0;
  14.     for(int i = 0; i < n; i++) {
  15.         int brojac = 0;
  16.         for(int j = 0; j < m; j++) {
  17.             if(mat[i][j] == 1) {
  18.                 brojac++;
  19.             }
  20.             else {
  21.                 if(brojac > maksimum) {
  22.                     maksimum = brojac;
  23.                 }
  24.  
  25.                 brojac = 0;
  26.             }
  27.             if(brojac > maksimum) {
  28.                     maksimum = brojac;
  29.                 }
  30.         }
  31.     }
  32.     for(int j = 0; j < m; j++) {
  33.         int brojac = 0;
  34.         for(int i = 0; i < n; i++) {
  35.             if(mat[i][j] == 1) {
  36.                 brojac++;
  37.             }
  38.             else {
  39.                 if(brojac > maksimum) {
  40.                     maksimum = brojac;
  41.                 }
  42.                 brojac = 0;
  43.             }
  44.             if(brojac > maksimum) {
  45.                 maksimum = brojac;
  46.             }
  47.  
  48.         }
  49.     }
  50.     printf("%d\n", maksimum);
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement