SHARE
TWEET

Untitled

a guest Dec 10th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int a[21][21],m,n,i,j, mn, mx, cm, cx;
  7.     cin >> m >> n;
  8.  
  9.     for (i=0; i<m; i++)
  10.       for (j=0; j<n; j++)
  11.           cin >> a[i][j];
  12.  
  13.     for (i=0; i<m; i++) {
  14.       mn=mx=a[i][0];
  15.       cm=cx=0;
  16.       for (j=1; j<n; j++) {
  17.         if (mn>a[i][j]) {
  18.           mn=a[i][j];
  19.           cm=j;
  20.         }
  21.         if (mx<a[i][j]) {
  22.           mx=a[i][j];
  23.           cx=j;
  24.         }
  25.       }
  26.       mn=a[i][0];
  27.       a[i][0]=a[i][cx];
  28.       a[i][cx]=mn;
  29.  
  30.       mx=a[i][n-1];
  31.       a[i][n-1]=a[i][cm];
  32.       a[i][cm]=mx;
  33.     }
  34.  
  35.      for (i=0; i<m; i++) {
  36.         cout << endl;
  37.       for (j=0; j<n; j++)
  38.         cout << a[i][j] << " ";
  39.      }
  40.     return 0;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top