AcWing 3279. 字符画
原题链接
中等
作者:
追着你行走
,
2021-04-03 11:33:23
,
所有人可见
,
阅读 451
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N=2010 ;
int a[N][N],b[N][N],c[N][N];
int m,n,q,p;
struct P{
int a,b,c;
friend bool operator == (P x,P y) {
return x.a==y.a&&x.b==y.b&&x.c==y.c;
}
}reset,pre;
int get(char ch) {
if(ch<='9') return ch-'0';
if(ch=='a') return 10;
if(ch=='b') return 11;
if(ch=='c') return 12;
if(ch=='d') return 13;
if(ch=='e') return 14;
if(ch=='f') return 15;
}
void print(int x) {
if(x<=9) printf("\\x%X",x+'0');//0要输出
else {
print(x/10);
printf("\\x%X",x%10+'0');
}
}
int main(){
cin>>m>>n>>p>>q;
for(int i=1;i<=n;i++) { //高
for(int j=1;j<=m;j++) { //宽
string s; cin>>s;
if(s.size()==2) {
a[i][j]=b[i][j]=c[i][j]=get(s[1])*16+get(s[1]);
} else if(s.size()==4) {
a[i][j] = get(s[1])*16+get(s[1]);
b[i][j] = get(s[2])*16+get(s[2]);
c[i][j] = get(s[3])*16+get(s[3]);
} else {
a[i][j] = get(s[1])*16+get(s[2]);
b[i][j] = get(s[3])*16+get(s[4]);
c[i][j] = get(s[5])*16+get(s[6]);
}
}
}
//print
for(int i=1;i<=n;i+=q) { //高
pre=reset;
for(int j=1;j<=m;j+=p) { //宽
P val={0,0,0};
for(int l=0;l<q;l++) {
for(int r=0;r<p;r++) {
val.a += a[l+i][r+j];
val.b += b[l+i][r+j];
val.c += c[l+i][r+j];
}
}
val.a/=p*q; val.b/=p*q; val.c/=q*p;
if(pre==val) {
cout<<"\\x20";
} else {
pre=val;
if(val==reset) {
cout<<"\\x1B\\x5B\\x30\\x6D\\x20";
} else {
cout<<"\\x1B\\x5B\\x34\\x38\\x3B\\x32\\x3B";
//多位数输出
print(val.a); cout<<"\\x3B";
print(val.b); cout<<"\\x3B";
print(val.c); cout<<"\\x6D\\x20";
}
}
}
if(!(pre==reset) ) cout<<("\\x1B\\x5B\\x30\\x6D\\x0A");
else cout<<"\\x0A"; //换行符输出
}
return 0;
}