PAT B -1066 image filter (15 minutes)

Click on the link full solution summary PAT B -AC

Title:
Image filter is unimportant to the image pixel color dyed background, so the important part is highlighted. Now given a monochrome image, the gray value is located in claim you all pixels within a designated color range are replaced with one specified color.

Input format:
input a given resolution image in the first row, i.e., two positive integers M and N (0 <M, N≤500) , the other is to be filtered gray value interval endpoints A and B (0 ≤A <B≤255), and replacing the tone value specified. Subsequently M rows, each row of the N gradation values given pixel, separated by a space therebetween. All the gradation values are within [0, 255] interval.

Output format:
image output filtering required. I.e. M output lines, each of the N pixel grayscale values, each representing three gradation values (e.g. 000 to be displayed in black), separated by a space therebetween. Line from beginning to end may not have the extra space.

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

My code:

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int main()
{
    int M,N,A,B,C;
    cin>>M>>N>>A>>B>>C;
    int img[M][N]={0};
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            int t;
            cin>>t;
            if(t>=A&&t<=B)t=C;
            img[i][j]=t;
        }
    }
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            printf("%03d",img[i][j]);
            if(j<N-1) cout<<" ";
        }
        cout<<endl;
    }

    return 0;
}

Published 82 original articles · won praise 1 · views 1669

Guess you like

Origin blog.csdn.net/qq_34451909/article/details/104914753