asgarlikanan

https://www.e-olymp.com/az/problems/2663

Aug 7th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.40 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/2663
  4. */
  5. #include <iostream>
  6. using namespace std;
  7. int main()
  8. {
  9.     //bubble sort
  10.     int n, say = 0;
  11.     cin>>n;
  12.     int a[n];
  13.     for(int i = 0; i < n; i++)
  14.         cin>>a[i];
  15.     for(int i = 0; i < n; i++){
  16.         for(int j = 0; j < n-1; j++){
  17.             if(a[j] > a[j+1]){
  18.                 swap(a[j], a[j+1]);
  19.                 say++; 
  20.             }
  21.         }
  22.     }
  23.     cout<<say<<endl;
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment