码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3257 Hello World!(位运算 & 模拟)

时间:2014-08-17 17:05:52      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:hdu   模拟   位运算   

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3257


Hello World!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 476    Accepted Submission(s): 180


Problem Description
Your task is to print ... er ... "Hello World" ... in a fantastic way -- using a beautiful font.

I‘ve sent you a nice font for you to use, but I‘m too busy to tell you how. Can you help yourself?
 

Input
The first line contains a single integer T (T <= 20), the number of test cases. 
Each case begins with an integer C (1 <= C <= 80) in a single line, then each of the following C lines contains five two-digit numbers in hex (letters will be in uppercase). Don‘t ask me what they mean, I‘m too busy...
 

Output
For each test case, print the case number in the first line, then followed by a blank line.
After that, print all T characters. Use a single blank column of spaces between two consecutive characters. Each line should have exactly 6C-1 character (again, don‘t ask me why).
Don‘t forget to print another blank line after the output of each test case.
 

Sample Input
2 11 7F 08 08 08 7F 38 54 54 54 18 00 41 7F 40 00 00 41 7F 40 00 38 44 44 44 38 00 00 00 00 00 3F 40 38 40 3F 38 44 44 44 38 7C 08 04 04 08 00 41 7F 40 00 38 44 44 48 7F 5 14 08 3E 08 14 04 02 01 02 04 40 40 40 40 40 04 02 01 02 04 14 08 3E 08 14
 

Sample Output
Case 1: # # ## ## # # ## # # # # # # # # # # # ### # # ### # # ### # ## # ## # ##### # # # # # # # # # # # ## # # # ## # # ##### # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ### ### ### ### # # ### # ### #### Case 2: # # # # # # # # # # # # # # # # # # ### ### # # # # # # # # #####
 

Source

思路:
首先想到这题是十六进制转换为二进制,我们先令tt为1,然后在用位运算向左移动(<<),
每移动一次就让所有的a[]和当前的tt&(与)一次,如果值为1那么就说明当前的a[i]的二进制
中在此处有1,也就是应该输出“#”,(主要是用到了位运算的‘<<’和‘&’);
再细细体味一下吧!


代码如下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
#define MAXN 80*5+47
int main()
{
    int t;
    int n;
    int a[MAXN];
    int cas = 0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i = 0; i < 5*n; i++)
        {
            scanf("%X",&a[i]);
        }
        int tt;
        printf("Case %d:\n\n",++cas);
        for(int i = 0; i < 7; i++)
        {
            tt = 1;
            tt <<= i;
            for(int j = 0; j < 5*n; j++)
            {
                if(j != 0 && j %5 == 0)
                    printf(" ");
                if(a[j] & tt)
                    printf("#");
                else
                    printf(" ");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


hdu 3257 Hello World!(位运算 & 模拟),布布扣,bubuko.com

hdu 3257 Hello World!(位运算 & 模拟)

标签:hdu   模拟   位运算   

原文地址:http://blog.csdn.net/u012860063/article/details/38639827

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!