fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. vector < vector < int > > finalVec;
  13.  
  14. void printArray(int p[], int n)
  15. {
  16. vector < int > vec;
  17. for (int i = 0; i < n; i++)
  18. vec.push_back(p[i]);
  19. finalVec.push_back(vec);
  20. return;
  21. }
  22.  
  23. void printAllUniqueParts(int n)
  24. {
  25. int p[n]; // An array to store a partition
  26. int k = 0; // Index of last element in a partition
  27. p[k] = n; // Initialize first partition as number itself
  28.  
  29. // This loop first prints current partition, then generates next
  30. // partition. The loop stops when the current partition has all 1s
  31. while (true)
  32. {
  33. // print current partition
  34. printArray(p, k+1);
  35.  
  36. // Generate next partition
  37.  
  38. // Find the rightmost non-one value in p[]. Also, update the
  39. // rem_val so that we know how much value can be accommodated
  40. int rem_val = 0;
  41. while (k >= 0 && p[k] == 1)
  42. {
  43. rem_val += p[k];
  44. k--;
  45. }
  46.  
  47. // if k < 0, all the values are 1 so there are no more partitions
  48. if (k < 0) return;
  49.  
  50. // Decrease the p[k] found above and adjust the rem_val
  51. p[k]--;
  52. rem_val++;
  53.  
  54.  
  55. // If rem_val is more, then the sorted order is violeted. Divide
  56. // rem_val in differnt values of size p[k] and copy these values at
  57. // different positions after p[k]
  58. while (rem_val > p[k])
  59. {
  60. p[k+1] = p[k];
  61. rem_val = rem_val - p[k];
  62. k++;
  63. }
  64.  
  65. // Copy rem_val to next position and increment position
  66. p[k+1] = rem_val;
  67. k++;
  68. }
  69. }
  70.  
  71.  
  72. int main() {
  73. int n,m,a[11][11],minim=INT_MAX,p[11];
  74. cin>>n;
  75. cin>>m;
  76. for(int i=0;i<11;i++){
  77. p[i]=1;
  78. }
  79. for(int i=0;i<n;i++){
  80. for(int j=0;j<m;j++){
  81. cin>>a[i][j];
  82. }
  83. }
  84. for(int j=0;j<m;j++){
  85. for(int i=0;i<n;i++){
  86. p[j]=p[j]*a[i][j];
  87.  
  88. }
  89. if(p[j]<minim){
  90. minim=p[j];
  91. }
  92. }
  93. for(int j=m-1;j>=0;j--){
  94. if(p[j]==minim){
  95. int k=0;
  96. for(int i=0;i<n;i++){
  97. for(int x=j+1;j<m;j++){
  98. a[i][x-1]=a[i][x];
  99. }
  100. }
  101. m--;
  102. if(k==0) {
  103. break;
  104. }
  105. }
  106.  
  107. }
  108. for(int i=0;i<n;i++){
  109. for(int j=0;j<m;j++){
  110. cout<<a[i][j]<<" ";
  111. }
  112. cout<<" "<<endl;}
  113.  
  114.  
  115. return 0;
  116. }
  117.  
  118.  
  119.  
Success #stdin #stdout 0s 5320KB
stdin
45
stdout