HDU3257 Hello World!【打印图案+位运算】

问题链接HDU3257 Hello World!

问题简述:参见上述链接。

问题分析:图案输出,关键在于读懂题意。

程序说明

需要注意16进制数的输入方法。

需要注意位运算。

需要注意用方便的数据表示(这里用一维数组比较方便)。

需要注意循环控制条件。

题记:(略)


AC的C++语言程序如下:

/* HDU3257 Hello World! */

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 7;
const int ROW = 80;
const int COL = 5;
int a[ROW * COL];

int main()
{
    int t, c;

    scanf("%d", &t);
    for(int k=1; k<=t; k++) {
        scanf("%d", &c);
        for(int i=0; i<c*COL; i++)
                scanf("%x", &a[i]);

        printf("Case %d:

", k);
        for(int i=0; i<N; i++) {
            int bit = (1 << i);
            for(int j=0; j<c*COL; j++) {
                if(j != 0 && j % COL == 0)
                    printf(" ");
                printf("%c", ((a[j] & bit) ? '#' : ' '));
            }
            printf("
");
        }
        printf("
");
    }

    return 0;
}



原文地址:https://www.cnblogs.com/tigerisland/p/7563766.html