NBUT-2013校赛·网络同步赛

来源:互联网 发布:走红网络的长板女孩 编辑:程序博客网 时间:2024/06/16 10:16
  • 这道题目我一开始还看不懂题意,看了好久才看懂,应该是水平问题,其实就是将一个16进制的数转换成8位2进制,在8为2进制中,如果是1就输出*,否则就输出0!这里运用到了位与运算!代码中有注释!
    代码如下:
    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main()
    {
        int t,n,m,i,j;
        char b[35][50];
        cin>>t;
        while(t--)
        {
            for(i=0; i<32; i++)
            {
                cin>>hex>>n;//c++中16进制数的输入!
                for(j=0; j<8; j++)
                {
                    if(n&(1<<j))b[j][i]='*';//n的第j位2进制数与1左移j位进行比较!根据位与运算法则!0&0=00&1=01&0=01&1=1;因为在计算机中当你输入一个16进制数时,计算机是以2进制数进行存储的!
                    else
                        b[j][i]='.';
                }
            }
            for(i=0; i<32; i++)
            {
                cin>>hex>>m;
                for(j=8; j<16; j++)
                {
                    if(m&(1<<(j-8)))b[j][i]='*';
                    else
                        b[j][i]='.';
                }
            }
            for(i=0; i<16; i++)
            {
                for(j=0; j<32; j++)
                {
                    cout<<b[i][j];
                }
                cout<<endl;
            }
        }
        return 0;


    }
    题目如下:
    There are a LCD (Liquid Crystal Display) on Ezreal's arm. The LCD is composed of liquid crystal, and the LCD is 16 lines and 48 rows. How did it work?

    The CPU will send a series of bytes to the LCD. A byte means to eight bits.When the LCD received the byte, it will show a page vertically. And each byte will display from bottom to top.

    For example, 0x01 0x9C 0xED will be shown as below:


    *.*....**.**.*...*..*.**


    Now give you 64 bytes, you should print it to the LCD from left to right and top to bottom. 32 columns in aBig Row (containing 8 rows).

  • 输入
  • First line contains an integer T (T < 100), means the test case.
    For each case, there are 2 lines which contain 64 hexadecimal numbers, and it is less than 0xff.
  • 输出
  • For each test case, print the LCD's status.
  • 样例输入
  • 101 9C ED DD 1A 2B CF CD C3 00 19 D0 5A 9F 56 13 E5 40 E5 46 E3 BD 4F A4 39 AF D8 2D 6F D4 54 361C B5 3C 24 9F 85 01 75 10 4B A0 00 77 44 77 7D 3B 82 57 47 DD DA DA 61 E5 FD F7 B7 1D E5 D3 A7
  • 样例输出
  • *.**.****.*..*.**.*.***.**.**.......***.*...****...**.*..*..*..*.***..**.....**.*.**.***.*.*****.*******..*.**.......**.*****....*.**.....******.....*..*.*..***..*..*..........*.*.**.***.**..*..**..***..**.*.*****.*...*.***..***..***..*.*..*.*.**.*.**..*...*..****.*..*.***.***..*********....*....*..*.*.****.**...**..********.*....****..***...******.**.*.*....*.....**...***..*..*...***.*..**...*.***.*.***..****.*..***...*..*.*.***......*****.*.*.......*.*..****..*********..**..*..**....*......*..***.****.***
原创粉丝点击