SHARE
TWEET

Untitled

a guest Sep 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("pachete.in");
  8. ofstream fout("pachete.out");
  9. int n,v[101];
  10. struct
  11. {
  12.     int m1,m2;
  13. }mutare[201];
  14. int main()
  15. {
  16.     int i,pozlib,j,aux,k=0;
  17.     cin>>n;
  18.     for(i=1; i<=n; i++)
  19.         cin>>v[i];
  20.     pozlib=n+1;
  21.     for(i=1; i<=n; i++)
  22.         if(v[i]!=i)
  23.         {
  24.             for(j=i+1; j<=n+1; j++)
  25.                 if(v[j]==i)
  26.                 {
  27.                     aux=j; break;
  28.                 }
  29.             if(i!=pozlib)
  30.             {
  31.                 mutare[++k].m1=i;
  32.                 mutare[k].m2=pozlib;
  33.                 v[pozlib]=v[i];
  34.             }
  35.             mutare[++k].m1=aux;
  36.             mutare[k].m2=i;
  37.             pozlib=aux;
  38.  
  39.         }
  40.     cout<<k<<'\n';
  41.     for(i=1; i<=k; i++)
  42.         cout<<mutare[i].m1<<" "<<mutare[i].m2<<'\n';
  43.     return 0;
  44. }
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