1066 图像过滤 (15 分)(超大时

1066 图像过滤 (15 分)
图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。

输入格式:
输入在第一行给出一幅图像的分辨率,即两个正整数 M 和 N(0<M,N≤500),另外是待过滤的灰度值区间端点 A 和 B(0≤A<B≤255)、以及指定的替换灰度值。随后 M 行,每行给出 N 个像素点的灰度值,其间以空格分隔。所有灰度值都在 [0, 255] 区间内。

输出格式:
输出按要求过滤后的图像。即输出 M 行,每行 N 个像素灰度值,每个灰度值占 3 位(例如黑色要显示为 000),其间以一个空格分隔。行首尾不得有多余空格。

输入样例:
3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255
结尾无空行
输出样例:
003 189 254 000 000
000 233 151 099 000
088 000 000 000 255
结尾无空行

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String st[] = in.readLine().split(" ");
        int M= Integer.parseInt(st[0]);
        int N = Integer.parseInt(st[1]);
        int A = Integer.parseInt(st[2]);
        int B = Integer.parseInt(st[3]);
        String instead = st[4];
     
        //格式化替代的值
        if(Integer.parseInt(instead)>=0 && Integer.parseInt(instead)<=9){
            instead="00"+instead;
        }
        if(Integer.parseInt(instead)>=10 && Integer.parseInt(instead)<=99){
            instead="0"+instead;
        }
     

        String arr[]= new String[M];
        for(int i =0;i<M;i++){
            arr[i]= in.readLine();
            String strings[]= arr[i].split(" ");
            //改变strings[j]的值,然后再进行拼接
            for (int j=0;j<N;j++){
                if(Integer.parseInt(strings[j])>=A && Integer.parseInt(strings[j]) <=B){
                    strings[j] = instead;
                       continue;
                }

                if(Integer.parseInt(strings[j])>=0 && Integer.parseInt(strings[j])<=9){
                    strings[j]="00"+strings[j];
                     continue;
                }
                if(Integer.parseInt(strings[j])>=10 && Integer.parseInt(strings[j])<=99){
                    strings[j]="0"+strings[j];
                    continue;
                }
            }
            arr[i] =strings[0];
            for(int j =1;j<N;j++){
                arr[i]+=" "+strings[j];
            }
        }
        for(int i=0;i<M;i++){
            System.out.println(arr[i]);
        }
    }
}



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String st[] = in.readLine().split(" ");
//        int M= Integer.parseInt(st[0]);
//        int N = Integer.parseInt(st[1]);
//        int A = Integer.parseInt(st[2]);
//        int B = Integer.parseInt(st[3]);
        //String instead = st[4];
        //格式化替代的值
        if(Integer.parseInt(st[4])>=0 && Integer.parseInt(st[4])<=9){
            st[4]="00"+st[4];
        }
        if(Integer.parseInt(st[4])>=10 && Integer.parseInt(st[4])<=99){
            st[4]="0"+st[4];
        }
        String arr[]= new String[Integer.parseInt(st[0])];
        for(int i =0;i<Integer.parseInt(st[0]);i++){
            arr[i]= in.readLine();
            String strings[]= arr[i].split(" ");
            //改变strings[j]的值,然后再进行拼接
            for (int j=0;j<Integer.parseInt(st[1]);j++){
                if(Integer.parseInt(strings[j])>=Integer.parseInt(st[2]) && Integer.parseInt(strings[j]) <=Integer.parseInt(st[3])){
                    strings[j] = st[4];
                        continue;
                }

                if(Integer.parseInt(strings[j])>=0 && Integer.parseInt(strings[j])<=9){
                    strings[j]="00"+strings[j];
                    continue;
                }
                if(Integer.parseInt(strings[j])>=10 && Integer.parseInt(strings[j])<=99){
                    strings[j]="0"+strings[j];
                    continue;
                }
            }
            arr[i] =strings[0];
            for(int j =1;j<Integer.parseInt(st[1]);j++){
                arr[i]+=" "+strings[j];
            }
        }
        for(int i=0;i<Integer.parseInt(st[0]);i++){
            System.out.println(arr[i]);
        }
    }
}



package PTA;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String st[] = in.readLine().split(" “);
//格式化替代的值
if(Integer.parseInt(st[4])>=0 && Integer.parseInt(st[4])<=9){
st[4]=“00”+st[4];
}
else if(Integer.parseInt(st[4])>=10 && Integer.parseInt(st[4])<=99){
st[4]=“0”+st[4];
}
for(int i =0;i<Integer.parseInt(st[0]);i++){
String strings[]= in.readLine().split(” “);
//改变strings[j]的值,然后再进行拼接
for (int j=0;j<Integer.parseInt(st[1]);j++){
if(Integer.parseInt(strings[j])>=Integer.parseInt(st[2]) && Integer.parseInt(strings[j]) <=Integer.parseInt(st[3])){
strings[j] = st[4];
continue;
}
if(Integer.parseInt(strings[j])>=0 && Integer.parseInt(strings[j])<=9){
strings[j]=“00”+strings[j];
continue;
}
if(Integer.parseInt(strings[j])>=10 && Integer.parseInt(strings[j])<=99){
strings[j]=“0”+strings[j];
continue;
}
}
StringBuffer sb = new StringBuffer();
sb.append(strings[0]);
for(int j =1;j<Integer.parseInt(st[1]);j++){
sb.append(” "+strings[j]);
}
System.out.println(sb);
}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超好的小白

没体验过打赏,能让我体验一次吗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值