Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- void sort(int *a, int n) //Пузырек
- {
- for (int i = 0; i < n - 1; i++)
- for (int j = n - 1; j > i; j--)
- if (a[j] < a[j - 1])
- swap(a[j], a[j - 1]);
- }
- int main()
- {
- int n;
- in >> n;
- int **mas = new int *[n]; //создали 2-ный массив
- for (int i = 0; i < n; i++)
- mas[i] = new int[n];
- for (int i = 0; i < n; i++) //записали числа из файла в массив
- for (int j = 0; j < n; j++)
- in >> mas[i][j];
- for (int i = 0; i < n; i++)
- {
- int *b = new int[n]; //создали вспомогательный массив для сортировки
- for (int j = 0; j < n; j++)
- b[j] = mas[j][i];
- sort(b, n); //проводим сортировку Пузырьком
- for (int j = 0; j < n; j++) //из вспомогательного обратно в основной
- mas[j][i] = b[j];
- delete b;
- }
- out << n << '\n';
- for (int i = 0; i < n; i++) //выводим массив в файл
- {
- for (int j = 0; j < n; j++)
- out << setw(5) << mas[i][j];
- out << '\n';
- }
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment