fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. short il;
  7. void funk(short tab[], short n)
  8. {
  9. for(int i=0; i<n-1; i++)
  10. {
  11. for(int j=i+1; j<n; j++)
  12. {
  13. if(tab[i]>tab[j])
  14. {
  15. swap(tab[i], tab[j]);
  16. il++;
  17. }
  18. }
  19. }
  20. cout << il<<endl;
  21. }
  22.  
  23. int main()
  24. {
  25. short *tab,n,u;
  26. cin>>u;
  27. while (u)
  28. {
  29. cin>>n;
  30. tab=new short [n];
  31. for (int i=0;i<n;i++)
  32. cin>>tab[i];
  33. funk (tab,n);
  34. u--;
  35. il=0;
  36. }
  37. }
Success #stdin #stdout 0s 4512KB
stdin
3
6
2 3 4 1 5 3 
3
3 2 1 
3
1 2 3 
stdout
5
3
0