Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. while(scanf("%d",&n)!=EOF)
  8. {
  9. int x[n+5],tmp,cnt=0;
  10. for(int i=1;i<=n;i++) scanf("%d",&x[i]);
  11.  
  12. for(int i=1;i<n;i++)
  13. {
  14. for(int j=1;j<n;j++)
  15. {
  16. if(x[j]>x[j+1])
  17. {
  18. tmp=x[j];
  19. x[j]=x[j+1];
  20. x[j+1]=tmp;
  21. cnt++;
  22. }
  23. }
  24. }
  25. printf("Minimum exchange operations : %d\n",cnt);
  26. }
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement