SHARE
TWEET

sortv

semkaegor4ik May 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <iomanip>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9. void sortubiv(int** a, int n,int k)
  10. {
  11.     for (int i = 0; i < n - 1; i++)
  12.     {
  13.         for (int j = i + 1; j < n; j++)
  14.             if (a[j][k] > a[i][k])
  15.                 swap(a[i][k], a[j][k]);
  16.     }
  17. }
  18.  
  19. void sortvozr(int** a, int n, int k)
  20. {
  21.     for (int i = 0; i < n - 1; i++)
  22.     {
  23.         for (int j = i + 1; j < n; j++)
  24.             if (a[j][k] < a[i][k])
  25.                 swap(a[i][k], a[j][k]);
  26.     }
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32.     int n, i, j;
  33.     in >> n;
  34.     int** mas = new int* [n];            
  35.     for (int i = 0; i < n; ++i)
  36.         mas[i] = new int[n];
  37.     for (int i = 0; i < n; ++i)
  38.         for (int j = 0; j < n; ++j)
  39.             in >> mas[i][j];
  40.  
  41.     for (int i = 0; i < n; ++i, out << "\n")
  42.         for (int j = 0; j < n; ++j)
  43.             out << " " << mas[i][j];
  44.     out << "\n";
  45.  
  46.     for (int i = 0; i < n; ++i)
  47.         for (int j = 0; j < n; ++j)
  48.             if (j % 2 == 0)
  49.                 sortvozr(mas, n, j);
  50.             else
  51.                 sortubiv(mas, n, j);
  52.  
  53.     for (int i = 0; i < n; ++i, out << "\n")
  54.         for (int j = 0; j < n; ++j)
  55.             out << " " << mas[i][j];
  56.     in.close();
  57.     out.close();
  58.     return 0;
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