Advertisement
ProgNeo

Untitled

Jun 15th, 2021
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int** A;
  8. int n;
  9.  
  10. int max = -1, x_of_max = -1, sum;
  11.  
  12. cin >> n;
  13.  
  14. A = new int* [n];
  15. for (int i = 0; i < n; i++) {
  16. A[i] = new int[n];
  17. for (int k = 0; k < n; k++) {
  18. cin >> A[i][k];
  19. }
  20. }
  21.  
  22. for (int j = 0; j < n; j++) {
  23. max = -1, x_of_max = -1;
  24. for (int i = j; i < n; i++) {
  25. sum = abs(A[i][0]);
  26. for (int k = 1; k < n; k++) {
  27. sum *= abs(A[i][k]);
  28. }
  29. if (sum > max) {
  30. max = sum;
  31. x_of_max = i;
  32. }
  33. }
  34. swap(A[j], A[x_of_max]);
  35. }
  36.  
  37. for (int i = 0; i < n; i++) {
  38. for (int j = 0; j < n; j++) {
  39. cout << A[i][j] << " ";
  40. }
  41. cout << "\n";
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement