B 1066 图像过滤(二维数组、定长度输出)

    技术2022-07-12  98

    题目

    思路

    用一个二维数组来储存,后续setw 加setfill实现输出000即可。

    AC代码

    #include<bits/stdc++.h> using namespace std; int main(){ int m; cin>>m; int n; cin>>n; int A,B,replace; cin>>A>>B>>replace; int a[m][n]={0}; int temp=0; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cin>>temp; a[i][j]=temp; if(temp>=A && temp<=B) a[i][j]=replace; } } for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cout<<setw(3)<<setfill('0')<<a[i][j]; if(j!=n-1) cout<<' '; } if(i!=m-1) cout<<endl; } return 0; }
    Processed: 0.024, SQL: 9