fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int counter=0,temp,test,n=0,a[1010];
  8. while(cin >> test)
  9. { n=0; counter=0;
  10. for(int i=0;i<test;i++)
  11. {
  12. cin >> a[i];
  13. n++;
  14. }
  15. for(int i=0;i<n;i++)
  16. {
  17. for(int j=0;j<n-1;j++)
  18. {
  19. if(a[j]>a[j+1])
  20. {
  21. temp=a[j];
  22. a[j]=a[j+1];
  23. a[j+1]=temp;
  24. counter++;
  25. }
  26. }
  27. }
  28. cout << "Minimum exchange operations : " << counter<<endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3300KB
stdin
3 
1 2 3
3
2 3 1
stdout
Minimum exchange operations : 0
Minimum exchange operations : 2