fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <limits.h>
  5.  
  6. #define maxn 1001
  7.  
  8. int arr[maxn][maxn];
  9. int m,n;
  10. bool col[maxn];
  11.  
  12.  
  13.  
  14. int find_max(){
  15. int j,i;
  16. int ans=INT_MIN;
  17. for(j=0;j<m;j++){
  18. for(i=0;i<n;i++){
  19. if(arr[j][i]>ans){
  20. ans=arr[j][i];
  21. }
  22. }
  23. }
  24. return ans;
  25. }
  26.  
  27. bool col_has_max(int col,int max_value){
  28. int j;
  29. for(j=0;j<m;++j){
  30. if(arr[j][col]==max_value){
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36.  
  37. int main(void) {
  38. int test;
  39. scanf("%d",&test);
  40. while(test--){
  41. // read arr
  42. scanf("%d%d",&m,&n);
  43. int i,j;
  44. for(j=0;j<m;++j){
  45. for(i=0;i<n;++i){
  46. scanf("%d",arr[j]+i);
  47. }
  48. }
  49.  
  50. int max=find_max();
  51.  
  52. for(i=0;i<n;++i){
  53. col[i]=col_has_max(i,max);
  54. }
  55.  
  56. // in ma tran
  57.  
  58. for(j=0;j<m;++j){
  59. for(i=0;i<n;++i){
  60. if(col[i]) continue; // col[i] chua max
  61. printf("%d ",arr[j][i]);
  62. }
  63. printf("\n");
  64. }
  65. }
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0s 6072KB
stdin
1
3 3
7 8 1
8 5 6
1 3 5
stdout
1 
6 
5