SHARE
TWEET

Untitled

a guest Nov 13th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int get_characteristic(const int* ar, int len) {
  8.  
  9.     int sum = 0;
  10.  
  11.     for (int i = 0; i < len; ++i) {
  12.         if (ar[i] < 0 && ar[i] % 2 != 0) {
  13.             sum -= ar[i];
  14.         }
  15.     }
  16.  
  17.     return sum;
  18. }
  19.  
  20. void print_matrix(int** ar, int n, int m) {
  21.     for (int i = 0; i < m; ++i) {
  22.         for (int j = 0; j < n; ++j) {
  23.             cout << setw(5) << ar[j][i] << " ";
  24.         }
  25.  
  26.         cout << "\n";
  27.     }
  28. }
  29.  
  30. int main() {
  31.     int n, m;
  32.  
  33.     cin >> n >> m;
  34.  
  35.     int** ar = new int*[m];
  36.  
  37.     for (int i = 0; i < n; ++i) {
  38.         ar[i] = new int[n];
  39.     }
  40.  
  41.     for (int i = 0; i < m; ++i) {
  42.         for (int j = 0; j < n; ++j) {
  43.             cin >> ar[j][i];
  44.         }
  45.     }
  46.  
  47.     sort(ar, ar + n, [m](int * lhs, int* rhs) { return get_characteristic(lhs, m) < get_characteristic(rhs, m); });
  48.  
  49.     print_matrix(ar, n, m);
  50.  
  51.     for (int i = 0; i < n; ++i) {
  52.         delete[] ar[i];
  53.     }
  54.  
  55.     delete[] ar;
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top