Advertisement
Guest User

Untitled

a guest
Nov 16th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void uredi(int &a, int &b)
  6. {
  7. a = a + b;
  8. b = -b;
  9. b = a + b;
  10. a = a - b;
  11. }
  12.  
  13. int main()
  14. {
  15. int a[6];
  16. int N, K,j;
  17. bool moze;
  18.  
  19. for (int i = 0; i < 6; i++) a[i] = -1000000001;
  20.  
  21. cin >> N >> K;
  22.  
  23. N--;
  24. while (N >= 0)
  25. {
  26. cin >> a[5];
  27.  
  28. moze = true;
  29. j = 0;
  30. while (moze)
  31. {
  32.  
  33. moze = false;
  34. for (int i = 5; i > j; i--)
  35. {
  36. if (a[i-1] < a[i])
  37. {
  38. uredi(a[i], a[i - 1]);
  39. moze = true;
  40. }
  41. }
  42. j++;
  43. }
  44. N--;
  45. }
  46.  
  47. for (int i = 0; i < K; i++) cout << a[i] << " ";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement