当前位置:网站首页>PAT B1066

PAT B1066

2022-06-25 19:56:00 Madness makes freedom

1066 Image filtering (15 branch )

Image filtering is to dye the unimportant pixels in the image into the background color , Make important parts stand out . Now give a black-and-white image , You are required to replace all pixel colors with a specified color when the gray value is within a specified range .

Input format :

Input gives the resolution of an image on the first line , That is, two positive integers M and N(0<M,N≤500), The other is the end point of the gray value interval to be filtered A and B(0≤A<B≤255)、 And the specified replacement gray value . And then M That's ok , Each line gives N The gray value of a pixel , Separated by spaces . All gray values are in [0, 255] Within the interval .

Output format :

Output the filtered image as required . The output M That's ok , Each row N Pixel gray value , Percentage of each gray value 3 position ( For example, black should be displayed as 000), Separated by a space . There must be no extra space at the beginning and end of the line .

sample input :

3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255

sample output :

003 189 254 000 000
000 233 151 099 000
088 000 000 000 255

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int m,n,a,b,ch;
    cin >> m >> n >> a >> b >> ch;
    int x;
    while(m--)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            if(x>=a&&x<=b)
                printf("%03d",ch);
            else
                printf("%03d",x);
            if(i<n-1)
                printf(" ");
            else
                printf("\n");
        }
    }
    return 0;
}

原网站

版权声明
本文为[Madness makes freedom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512260824.html