天天看點

PAT-BASIC1066——圖像過濾

我的PAT-BASIC代碼倉:https://github.com/617076674/PAT-BASIC

原題連結:https://pintia.cn/problem-sets/994805260223102976/problems/994805266514558976

題目描述:

PAT-BASIC1066——圖像過濾

知識點:格式化輸出

思路:按題述程式設計即可

輸出資料的時候需要格式化輸出,前面補0直至數字長度達到3位。

時間複雜度是O(M * N)。空間複雜度是O(1)。

C++代碼:

#include<iostream>

using namespace std;

int main(){
	int M, N, A, B, newColor;
	scanf("%d %d %d %d %d", &M, &N, &A, &B, &newColor);
	
	int tempColor;
	for(int i = 0; i < M; i++){
		for(int j = 0; j < N; j++){
			scanf("%d", &tempColor);
			if(tempColor >= A && tempColor <= B){
				tempColor = newColor;
			}
			printf("%03d", tempColor);
			if(j != N - 1){
				printf(" ");
			}
		}
		printf("\n");
	}
}
           

C++解題報告:

PAT-BASIC1066——圖像過濾