Infiniti_Inter

2. Выбором (Olya)

Jan 21st, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. ifstream in("input.txt");
  7. ofstream out("output.txt");
  8.  
  9. void choicesSort(int* a, int length_array) // сортировка выбором
  10. {
  11.     for (int i = 0; i < length_array; i++)
  12.     {
  13.         int temp = a[0]; // временная переменная для хранения значения перестановки
  14.         for (int j = i + 1; j < length_array; j++)
  15.         {
  16.             if (a[i] > a[j])
  17.             {
  18.                 temp = a[i];
  19.                 a[i] = a[j];
  20.                 a[j] = temp;
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     int n;
  29.     in >> n;
  30.     int ** a = new int* [n];
  31.     for (int i = 0; i < n; ++i)
  32.         a[i] = new int[n];
  33.     for (int i = 0; i < n; ++i)
  34.         for (int j = 0; j < n; ++j)
  35.             in >> a[i][j];
  36.     for (int i = 0; i < n; ++i)
  37.         choicesSort(a[i], n);
  38.  
  39.     for (int i = 0; i < n; ++i)
  40.     {
  41.         for (int j = 0; j < n; ++j)
  42.             out << a[i][j] << "\t";
  43.         out << endl;
  44.     }
  45.     /*
  46.     sample input
  47.     5
  48.     5 4 3 2 1
  49.     12 32 15 32 72
  50.     32 12 23 1 64
  51.     23 4 6 18 53
  52.     76 42 64 56 67
  53.     */
  54.    
  55. }
Add Comment
Please, Sign In to add comment