Advertisement
Josif_tepe

Untitled

Aug 24th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, const char * argv[]) {
  4.     int n, m;
  5.     scanf("%d%d", &n, &m);
  6.     int mat[n][m];
  7.    
  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 najgolem_zbir = 0;
  14.     int najgolema_kolona = 0;
  15.    
  16.     for(int j = 0; j < m; j++) {
  17.         int zbir = 0;
  18.         for(int i = 0; i < n; i++) {
  19.             zbir += mat[i][j];
  20.         }
  21.         if(zbir > najgolem_zbir) {
  22.             najgolem_zbir = zbir;
  23.             najgolema_kolona = j;
  24.         }
  25.     }
  26.     int najgolem_zbir2 = 0;
  27.     int najgolema_kolona2 = 0;
  28.     for(int j = 0; j < m; j++) {
  29.         int zbir = 0;
  30.         for(int i = 0; i < n; i++) {
  31.             zbir += mat[i][j];
  32.         }
  33.         if(zbir > najgolem_zbir2 && j != najgolema_kolona) {
  34.             najgolem_zbir2 = zbir;
  35.             najgolema_kolona2 = j;
  36.         }
  37.     }
  38.    
  39.     for(int i = 0; i < n; i++) {
  40.         int pom = mat[i][najgolema_kolona];
  41.         mat[i][najgolema_kolona] = mat[i][najgolema_kolona2];
  42.         mat[i][najgolema_kolona2] = pom;
  43.     }
  44.     for(int i = 0; i < n / 2; i++) {
  45.         int pom = mat[i][najgolema_kolona];
  46.         mat[i][najgolema_kolona] = mat[n - i - 1][najgolema_kolona];
  47.         mat[n - i - 1][najgolema_kolona] = pom;
  48.     }
  49.     for(int i = 0; i < n / 2; i++) {
  50.         int pom = mat[i][najgolema_kolona2];
  51.         mat[i][najgolema_kolona2] = mat[n - i - 1][najgolema_kolona2];
  52.         mat[n - i - 1][najgolema_kolona2] = pom;
  53.     }
  54.     for(int i = 0; i < n; i++) {
  55.         for(int j = 0; j < m; j++) {
  56.             printf("%d ", mat[i][j]);
  57.         }
  58.         printf("\n");
  59.     }
  60.     return 0;
  61.    
  62. }
  63. /*
  64. 1 2 3 4 5 6 7 8
  65. 2 1 2 3 4 5 6 7
  66. 3 4 5 6 7 8 9 10
  67. 4 5 6 7 8 9 10 0
  68. 5 6 7 8 9 10 0 1
  69. 6 7 8 9 10 0 1 2
  70.  **/
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement