Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- void choicesSort(int* a, int length_array) // сортировка выбором
- {
- for (int i = 0; i < length_array; i++)
- {
- int temp = a[0]; // временная переменная для хранения значения перестановки
- for (int j = i + 1; j < length_array; j++)
- {
- if (a[i] > a[j])
- {
- temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- }
- }
- }
- int main()
- {
- int n;
- in >> n;
- int ** a = new int* [n];
- for (int i = 0; i < n; ++i)
- a[i] = new int[n];
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- in >> a[i][j];
- for (int i = 0; i < n; ++i)
- choicesSort(a[i], n);
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < n; ++j)
- out << a[i][j] << "\t";
- out << endl;
- }
- /*
- sample input
- 5
- 5 4 3 2 1
- 12 32 15 32 72
- 32 12 23 1 64
- 23 4 6 18 53
- 76 42 64 56 67
- */
- }
Add Comment
Please, Sign In to add comment