fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, k, i;
  6. cin >> n;
  7. int dulces[n];
  8. for (i=0; i<n; i++) cin >> dulces[i];
  9. cin >> k;
  10. int valMin = k-3;
  11. int valMax = k+3;
  12. for (i=0; i<n; i++)
  13. if (dulces[i] >= valMin && dulces[i] <= valMax)
  14. cout << dulces[i] << ' ';
  15. return 0;
  16. }
Success #stdin #stdout 0s 5288KB
stdin
8
10 25 13 15 12 8 7 6
10
stdout
10 13 12 8 7