Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int** A;
- int n;
- int max = -1, x_of_max = -1, sum;
- cin >> n;
- A = new int* [n];
- for (int i = 0; i < n; i++) {
- A[i] = new int[n];
- for (int k = 0; k < n; k++) {
- cin >> A[i][k];
- }
- }
- for (int j = 0; j < n; j++) {
- max = -1, x_of_max = -1;
- for (int i = j; i < n; i++) {
- sum = abs(A[i][0]);
- for (int k = 1; k < n; k++) {
- sum *= abs(A[i][k]);
- }
- if (sum > max) {
- max = sum;
- x_of_max = i;
- }
- }
- swap(A[j], A[x_of_max]);
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << A[i][j] << " ";
- }
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement