Advertisement
llvlleo1810

Loại bỏ hàng và cột có tổng lớn nhất ra khỏi ma trận

Aug 6th, 2019
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. INPUT
  2. 3 3
  3. 1 2 4
  4. 3 4 0
  5. 6 3 5
  6. OUTPUT
  7. 2 4
  8. 4 0
  9.  
  10. #include<stdio.h>
  11. int tmax(int a[],int n)
  12. {
  13.     int max=a[0],vt=0;
  14.     for(int i=1;i<n;i++)
  15.     {
  16.         if(a[i]>max)
  17.         {
  18.             max=a[i];
  19.             vt=i;
  20.         }
  21.     }
  22.     return vt;
  23. }
  24. int main()
  25. {
  26.     int m,n,a[100][100],h[100]={0},c[100]={0},mh,mc,sum=0;
  27.     scanf("%d%d",&m,&n);
  28.     for(int i=0;i<m;i++)
  29.     {
  30.         for(int j=0;j<n;j++)
  31.         {
  32.             scanf("%d",&a[i][j]);
  33.         }
  34.     }
  35.     for(int i=0;i<m;i++)
  36.     {
  37.         for(int j=0;j<n;j++)
  38.         {
  39.             h[i]+=a[i][j];
  40.             c[j]+=a[i][j];
  41.         }
  42.     }
  43.     mh=tmax(h,m);
  44.     mc=tmax(c,n);
  45.     for(int i=0;i<m;i++)
  46.     {
  47.         if(i==mh)
  48.         {
  49.             continue;
  50.         }
  51.         for(int j=0;j<n;j++)
  52.         {
  53.             if(j==mc)
  54.             {
  55.                 continue;
  56.             }
  57.             printf("%d ",a[i][j]);
  58.         }
  59.         printf("\n");
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement