1066 图像过滤


solution

cpp 复制代码
#include<iostream>
using namespace std;
const int maxn = 510;
int arr[maxn][maxn];
int main(){
	int n, m, 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", &arr[i][j]);
			if(arr[i][j] >= a && arr[i][j] <= b) arr[i][j] = x;
		}
	} 
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			printf("%03d", arr[i][j]);
			if(j != n - 1) printf(" ");
		}
		if(i != m - 1) printf("\n");
	}
	return 0;
}

or

cpp 复制代码
#include<iostream>
using namespace std;
int main(){
	int n, m, a, b, x, t;
	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", &t);
			if(t >= a && t <= b) t = x;
			printf("%03d", t);
			if(j != n - 1) printf(" ");
		}
		if(i != m - 1) printf("\n");
	} 
	return 0;
}
相关推荐
Jerry3 小时前
LeetCode 28. 找出字符串中第一个匹配项的下标
算法
Jerry5 小时前
LeetCode 459. 重复的子字符串
算法
哥不想学算法7 小时前
【C++】字符串字面量拼接
开发语言·c++
海石7 小时前
1500分的题目,确实有实力,不过还是我略胜一筹
算法·leetcode
海石7 小时前
【记忆化搜索】条条大路通AC,走好适合你的那一条,走到后再考虑走得快
算法·leetcode
Jerry9 小时前
LeetCode 151. 反转字符串中的单词
算法
a11177612 小时前
LM 算法迭代过程动画演示(SLAM)
算法
头茬韭菜12 小时前
Context 的生死抉择:四层压缩、截断算法与 Session Memory
算法·ai
Jerry12 小时前
LeetCode 541. 反转字符串 II
算法
Jerry12 小时前
LeetCode 344. 反转字符串
算法