Advertisement
Farjana_akter

Untitled

Jul 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<long long int>v;
  5. int main()
  6. {
  7. freopen("in.txt","r",stdin);
  8. freopen("out.txt","w",stdout);
  9. long long int n,i,t,j,k,a;
  10. cin>>t;
  11. while(t--)
  12. {
  13. cin>>n;
  14. v.clear();
  15. for(i=0;i<n;i++)
  16. {
  17. cin>>a;
  18. v.push_back(a);
  19. }
  20. long long int count=0;
  21. for(i=0;i<n;i++)
  22. {
  23. for(j=i+1;j<n;j++)
  24. {
  25. if(v[i]>v[j])
  26. {
  27. swap(v[i],v[j]);
  28. count++;
  29. }
  30. }
  31. }
  32. cout<<"Optimal train swapping takes "<<count<<" swaps."<<endl;
  33. }
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement