博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D - Hexadecimal View HDU - 4054(模拟)进制转换
阅读量:4207 次
发布时间:2019-05-26

本文共 2167 字,大约阅读时间需要 7 分钟。

Hexadecimal is very important and useful for computer programmers. You are requested to provide a hexadecimal view for given data. The hexadecimal view is made up of one or more rows. Every row except the last one represents 16 characters. Each row consists of three columns separated by a space: 
* addr: the 4-digit hexadecimal beginning address of this row. 
* dump: the hexadecimal representation of this row, separating every two characters by a whitespace. If there are less than 16 characters in the last row, pad it with spaces. 
* text: the ASCII translation of this row, with uppercase characters converted to lowercase and lowercase characters converted to uppercase. 
Use lowercase for the letter digits. See sample for more details. 
Input
There are multiple test cases. Each line is a test case. The line is made up of no less than 1 and no more than 4096 printable characters including spaces. 
Output
For each test case, output its hexadecimal view. Do not output any extra spaces after the last character of text. 
Sample Input
Hex Dump#include 
printf("Hello, World!\n");main = do getLine >>= print . sum . map read . words
Sample Output
0000: 4865 7820 4475 6d70                     hEX dUMP0000: 2369 6e63 6c75 6465 203c 6373 7464 696f #INCLUDE 
0000: 7072 696e 7466 2822 4865 6c6c 6f2c 2057 PRINTF("hELLO, w0010: 6f72 6c64 215c 6e22 293b ORLD!\N");0000: 6d61 696e 203d 2064 6f20 6765 744c 696e MAIN = DO GETlIN0010: 6520 3e3e 3d20 7072 696e 7420 2e20 7375 E >>= PRINT . SU0020: 6d20 2e20 6d61 7020 7265 6164 202e 2077 M . MAP READ . W0030: 6f72 6473 ORDS

输出分三列。 
第一列 : 0000: 表示当前语句的第1行 0010:表示当前语句的第二行。 以为规定一行只能输出16个字节, 所以代码中的一行可能要多行输出。 比如 该行代码一行有110字节 110 = 6 * 16 + 14就要输出 06e0: 
第二列: 一个字节8位, 一个16进制的数 4位, 所以每两个 16进制数就代表一个字符。 
不满16个字节,要输出空格。 
第三列: 把代码的的大小写互换。 每16个就要换行, 输出完一行代码也要换行(后面无多余的空格)。 
列与列之间有一个空格。

利用%04x 可以把数字。字符转化为16进制直接输出。

char s[50000+10];char get_(char a){    if(a>='a' && a<='z') return char(a-32);    else if(a>='A' && a<='Z') return char(a+32);    return a;}int main(){    ios::sync_with_stdio(false);    while(gets(s))    {        int len=strlen(s);        for(int i=0;i

转载地址:http://veali.baihongyu.com/

你可能感兴趣的文章
1.idea中Maven创建项目及2.对idea中生命周期的理解3.pom文件夹下groupId、artifactId含义
查看>>
LeetCode-栈|双指针-42. 接雨水
查看>>
stdin,stdout,stderr详解
查看>>
Linux文件和设备编程
查看>>
文件描述符
查看>>
终端驱动程序:几个简单例子
查看>>
登录linux密码验证很慢的解决办法
查看>>
fcntl函数总结
查看>>
HTML条件注释
查看>>
Putty远程服务器的SSH经验
查看>>
内核态与用户态
查看>>
使用mingw(fedora)移植virt-viewer
查看>>
趣链 BitXHub跨链平台 (4)跨链网关“初介绍”
查看>>
C++ 字符串string操作
查看>>
MySQL必知必会 -- 了解SQL和MySQL
查看>>
MySQL必知必会 -- 使用MySQL
查看>>
MySQL必知必会 -- 数据检索
查看>>
MySQL必知必会 -- 排序检索数据 ORDER BY
查看>>
MySQL必知必会 -- 数据过滤
查看>>
MYSQL必知必会 -- 用通配符进行过滤
查看>>