字符画

Posted liulex

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符画相关的知识,希望对你有一定的参考价值。

字符画

通過樣例猜題意系列

注意讀題:每輸出完一行需要恢復背景色

這題用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]=;
    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((
));
    }
}
/*
2 2
2 1
#111111
#0
#000000
#000
x1Bx5Bx34x38x3Bx32x3Bx38x3Bx38x3Bx38x6Dx20x1Bx5Bx30x6Dx0Ax20x0A
x1Bx5Bx34x38x3Bx32x3Bx38x3Bx38x3Bx38x6Dx20x1Bx5Bx30x6Dx0Ax20x0A


*/

 

以上是关于字符画的主要内容,如果未能解决你的问题,请参考以下文章

一行代码画出字符心形表白

用python绘制字符画

图片:“给你五十行代码把我变成字符画!” 程序:“太多了,一半都用不完!”

带有神秘附加字符的 Javascript Date getTime() 代码片段

Python 视频转字符画 - 进阶

python学习---50行代码实现图片转字符画1