Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // готово
  2. #include <iostream>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int c = 0;
  7.  
  8. int main() {
  9. int arr[100000];
  10. srand(0);
  11. int n;
  12. cin >> n;
  13. for (int k = 0; k < 7; ++k) {
  14. for (int i = 0; i < n; ++i) {
  15. arr[i] = rand() % 10000;
  16. }
  17. c = 0;
  18. for (int i = 0; i < n; ++i) {
  19. c += 1;
  20. int cnt = 0;
  21. for (int j = i + 1; j < n; ++j) {
  22. ++c;
  23. if (arr[i] > arr[j]) {
  24. cnt++;
  25. c += 3;
  26. swap(arr[i], arr[j]);
  27. }
  28. }
  29. if (cnt == 0) break;
  30. c += 1;
  31. }
  32. cout << c << endl;
  33. }
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement