fork(2) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. int n, nr,count, temp;
  8. std::cin >> n;
  9. for (int i = 0; i < n; ++i)
  10. {
  11. count = 0;
  12. std::cin >> nr;
  13. std::vector<int> container(nr, -1);
  14. int j;
  15. for (j = 0; j < nr; ++j)
  16. {
  17. std::cin >> temp;
  18. container[j] = temp;
  19. }
  20.  
  21. for (j = 0; j < nr; ++j)
  22. for (int k = 1; k < nr - j; ++k)
  23. {
  24. if (container[k - 1] > container[k])
  25. {
  26. std::swap(container[k], container[k - 1]);
  27. ++count;
  28. }
  29. }
  30. std::cout << count << std::endl;
  31. }
  32. return 0;
  33. }
  34.  
Runtime error #stdin #stdout #stderr 0s 4396KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc