1. #include<iostream>
    2. #include<algorithm>
    3. using namespace std;
    4. void filter_middle(int w, int n) {
    5. int a[100] = { 0 }; int b[100] = { 0 }; int c[20];
    6. for (int i = 0; i < n; i++) {
    7. cin >> a[i]; b[i] = a[i];
    8. }
    9. int begin = 0; int mid = (begin + begin + w) / 2;
    10. while (begin <= n - w) {//最大滤波边界 小于 滤波窗口长度
    11. for (int i = 0; i < w; i++) c[i] = a[begin + i];// 取出子序列,原序列保持不变
    12. stable_sort(c, c+w);
    13. b[mid+begin] = c[mid];
    14. begin++;
    15. }
    16. for (int i = 0; i < n; i++) {
    17. cout << b[i]<<" ";
    18. }
    19. cout << endl;
    20. }
    21. int main() {
    22. int w;
    23. int n;
    24. while (cin>>w>>n) {
    25. if (w % 2 == 0)printf("ERROR\n");
    26. else
    27. filter_middle(w, n);
    28. }
    29. return 0;
    30. }

    image.png
    image.png