Advertisement
hadiuzzaman65

uva 10327

Jul 5th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. int main()
  6. { //freopen("input.txt","r",stdin);
  7.   int ar[1000];
  8.    int n;
  9.  
  10.   while(scanf("%d",&n)==1)
  11.   {
  12.     for(int i=0; i<n; i++)
  13.         cin>>ar[i];
  14.       int count=0;
  15.     for(int i=0; i<n-1; i++)
  16.     {
  17.         for(int j=0; j<n-1-i; j++)
  18.         {
  19.             if(ar[j]>ar[j+1])
  20.             {
  21.                 count++;
  22.                 swap(ar[j],ar[j+1]);
  23.             }
  24.         }
  25.     }
  26.     cout<< "Minimum exchange operations : "<<count<<endl;
  27.  
  28.   }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement