fork download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <climits>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10.  
  11. // capture list: danh sách các biến bên ngoài được lamda sử dụng, lamda có thể truy cập các biến trong phạm vi nơi nó
  12. // được tạo ra, [=],[&]
  13.  
  14. // pass by reference
  15.  
  16. // pass by value
  17.  
  18. int main() {
  19. ios_base::sync_with_stdio(false);
  20. cin.tie(NULL);
  21. int X;
  22. int n;
  23. if (!(cin >> n >> X)) return 0;
  24. vector<int> a(n);
  25. for (int i = 0; i < n; i++) {
  26. cin >> a[i];
  27. }
  28. vector<int> b = a;
  29. sort(a.begin(), a.end(), [X](int a, int b) {
  30. int d1 = abs(a - X);
  31. int d2 = abs(b - X);
  32. if (d1 != d2) {
  33. return d1 < d2;
  34. }
  35. return a < b;
  36. });
  37. for (int i = 0; i < n; i++) {
  38. cout << a[i] << (i == n - 1 ? "" : " ");
  39. }
  40. cout << "\n";
  41. sort(b.begin(), b.end(), [](int a, int b) {
  42. if (a % 2 == 0 && b % 2 != 0) return true;
  43. if (a % 2 != 0 && b % 2 == 0) return false;
  44. if (a % 2 == 0 && b % 2 == 0) return a < b;
  45. return a > b;
  46. });
  47. for (int i = 0; i < n; i++) {
  48. cout << b[i] << (i == n - 1 ? "" : " ");
  49. }
  50. cout << "\n";
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty