我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805266514558976
题目描述:
知识点:格式化输出
思路:按题述编程即可
输出数据的时候需要格式化输出,前面补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++解题报告: