Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // Counting inversions
  4. //
  5. // Created by Panagiotis Hadjicostas on 17/08/2019.
  6. // Copyright © 2019 Panagiotis Hadjicostas. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. using namespace std;
  11. int main() {
  12.  
  13. int n;
  14.  
  15. cin>>n;
  16.  
  17. int i,j,a[n];
  18. int counter=0;
  19. for(i=0;i<n;i++){
  20. cin>>a[i];
  21. if(i>0){
  22. for(j=0;j<i;j++){
  23. if(a[i]<a[j]){
  24. counter++;
  25. }
  26. }
  27. }
  28. }
  29.  
  30. cout<<counter<<endl;
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement