Imran1107048

Reversort

Mar 26th, 2021 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[110];
  5.  
  6. int main()
  7. {
  8. int ca;
  9. cin >> ca;
  10. for(int tc=1;tc<=ca;tc++){
  11. int n;
  12. cin >> n;
  13. for(int i=0;i<n;i++){
  14. cin >> a[i];
  15. }
  16.  
  17. int cnt = 0;
  18. for(int i=0;i<n-1;i++){
  19. int index = i;
  20. int mn = a[i];
  21. for(int j=i+1;j<n;j++){
  22. if(a[j]<mn){
  23. mn = a[j];
  24. index = j;
  25. }
  26. }
  27. cnt += index - i + 1;
  28. //cout << index << endl;
  29.  
  30. for(int k=i; k<index; k++, index--){
  31. swap(a[k], a[index]);
  32. }
  33.  
  34. // for(int j=0;j<n;j++)
  35. // cout << a[j] << " ";
  36. // cout << endl;
  37. }
  38.  
  39. cout << "Case #" << tc << ": " << cnt << endl;
  40. }
  41. }
  42.  
Add Comment
Please, Sign In to add comment