通過樣例猜題意系列
注意讀題:每輸出完一行需要恢復背景色
這題用cout瘋狂爆零什麽鬼
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int A[2004][2003][3];
int n, m, p, q;
string color;
int ati(char c)
{
if (c >= 'A' && c <= 'Z')
{
return c - 'A' + 10;
}
else
return c - '0';
}
char* reset = "\\x1B\\x5B\\x30\\x6D";
char* ESC = "\\x1B";
void ito(int x)
{
//printf("\\x%02X",x);
//cout << "\\x";
char s[3] ;
s[2]='\0';
int a = x % 16;
x /= 16;
int b = x % 16;
if (a >= 10)
{
s[1] = char(a - 10 + 'A');
}
else
s[1] = char(a + '0');
if (b >= 10)
{
s[0] = char(b - 10 + 'A');
}
else
s[0] = char(b + '0');
printf("\\x%s",s);
}
void init(int x, int y)
{
int len = color.length();
for (int i = 0; i < len; i++)
{
if (color[i] >= 'a' && color[i] <= 'z')
color[i] = char(color[i] - 'a' + 'A');
}
if (len == 7)
{
A[x][y][0] = ati(color[1]) * 16 + ati(color[2]);
A[x][y][1] = ati(color[3]) * 16 + ati(color[4]);
A[x][y][2] = ati(color[5]) * 16 + ati(color[6]);
}
else if (len == 4)
{
A[x][y][0] = ati(color[1]) * 16 + ati(color[1]);
A[x][y][1] = ati(color[2]) * 16 + ati(color[2]);
A[x][y][2] = ati(color[3]) * 16 + ati(color[3]);
}
else
{
A[x][y][0] = A[x][y][1] = A[x][y][2] = ati(color[1]) * 16 + ati(color[1]);
}
}
int B[2005][2005][3];
void del(int x)
{
int a = x % 10;
x /= 10;
int b = x % 10;
x /= 10;
int d = x;
char c;
c = (d + '0');
if (d != 0)
{
ito(c);
}
c = (b + '0');
if (b != 0 || d != 0)
{
ito(c);
}
c = (a + '0');
ito(c);
}
int main()
{
ios::sync_with_stdio(false);
cin >> m >> n >> p >> q;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> color;
init(i, j);
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
for (int k = 0; k < 3; k++)
B[i / q][j / p][k] += A[i][j][k];
}
}
for (int i = 0; i < n / q; i++)
{
for (int j = 0; j < m / p; j++)
{
for (int k = 0; k < 3; k++)
{
B[i][j][k] /= (p * q);
}
}
}
int be[] = {0,0,0};
for (int i = 0; i < n / q; i++)
{
be[0] = be[1] = be[2] = 0;
for (int j = 0; j < m / p; j++)
{
if ((B[i][j][0] != be[0] || B[i][j][1] != be[1] || B[i][j][2] != be[2])&&(B[i][j][0] == 0 && B[i][j][1] == 0 && B[i][j][2] == 0))
{
printf("%s",reset);
}
else
{
if (B[i][j][0] != be[0] || B[i][j][1] != be[1] || B[i][j][2] != be[2])
{
printf("%s",ESC); ito('[') ; ito('4') ;ito('8') ; ito(';') ; ito('2') ; ito(';');
del(B[i][j][0]);
ito(';');
del(B[i][j][1]);
ito(';');
del(B[i][j][2]);
ito('m');
}
}
for (int k = 0; k < 3; k++)
{
be[k] = B[i][j][k];
}
ito((' '));
}
if (be[0] != 0 || be[1] != 0 || be[2] != 0)
{
printf("%s",reset);
}
ito(('\n'));
}
}
/*
2 2
2 1
#111111
#0
#000000
#000
\x1B\x5B\x34\x38\x3B\x32\x3B\x38\x3B\x38\x3B\x38\x6D\x20\x1B\x5B\x30\x6D\x0A\x20\x0A
\x1B\x5B\x34\x38\x3B\x32\x3B\x38\x3B\x38\x3B\x38\x6D\x20\x1B\x5B\x30\x6D\x0A\x20\x0A
*/