PAT (Basic Level) Practise (中文)1066. 图像过滤(15)
2017-11-15 10:46
671 查看
1066. 图像过滤(15)
时间限制400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。
输入格式:
输入在第一行给出一幅图像的分辨率,即两个正整数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
#include <cstdio> const int maxn=510; int a[maxn][maxn]; int main(){ int m,n,A,B,x; scanf("%d%d%d%d%d",&m,&n,&A,&B,&x); for(int i=0;i<m;i++) for(int j=0;j<n;j++) scanf("%d",&a[i][j]); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(a[i][j]>=A&&a[i][j]<=B) a[i][j]=x; } } for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ printf("%03d",a[i][j]); if(j<n-1) printf(" "); else printf("\n"); } } return 0; }
相关文章推荐
- PAT (Basic Level) Practise (中文) 1066. 图像过滤(15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15)
- PAT (Basic Level) Practise (中文)1071. 小赌怡情(15)
- PAT (Basic Level) Practise (中文)1001. 害死人不偿命的(3n+1)猜想 (15) C语言
- PAT (Basic Level) Practise (中文)-1036. 跟奥巴马一起编程(15)
- PAT (Basic Level) Practise (中文)1026. 程序运行时间(15) C语言
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15)
- PAT (Basic Level) Practise (中文) 1026. 程序运行时间(15)
- PAT (Basic Level) Practise (中文) 1026. 程序运行时间(15)
- PAT (Basic Level) Practise (中文)- 1011. A+B和C (15)
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15) C语言
- PAT (Basic Level) Practise (中文)1071. 小赌怡情(15)
- PAT (Basic Level) Practise (中文)-1031. 查验身份证(15)
- PAT (Basic Level) Practise (中文) 1051. 复数乘法 (15)
- PAT (Basic Level) Practise (中文)- 1021. 个位数统计 (15)
- PAT (Basic Level) Practise (中文)1031. 查验身份证(15)
- PAT (Basic Level) Practise (中文)1041. 考试座位号(15)
- PAT (Basic Level) Practise (中文)1011. A+B和C (15)
- PAT (Basic Level) Practise (中文) 1046. 划拳(15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15)