anon20016

A

Nov 14th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <stack>
  8.  
  9. using namespace std;
  10.  
  11. int a[5001];
  12.  
  13. int main() {
  14.  
  15.  
  16. int n;
  17. cin >> n;
  18. for (int i = 0; i < n; i++) {
  19. cin >> a[i];
  20. }
  21. int k = 1;
  22. while (k) {
  23. k = 0;
  24. for (int i = 0; i < n - 1; i++) {
  25. if (a[i] > a[i + 1]) {
  26. swap(a[i], a[i + 1]);
  27. k++;
  28. }
  29. }
  30. }
  31. for (int i = 0; i < n; i++) {
  32. cout << a[i] << ' ';
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment