HDOJ4054 Hexadecimal View[编码题]
2014-12-03 19:18
344 查看
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output its hexadecimal view. Do not output any extra spaces after the last character of text.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
C语言格式化输出的时候用%x就自动输出成十六进制了。
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output its hexadecimal view. Do not output any extra spaces after the last character of text.
[align=left]Sample Input[/align]
Hex Dump #include <cstdio> printf("Hello, World!\n"); main = do getLine >>= print . sum . map read . words
[align=left]Sample Output[/align]
0000: 4865 7820 4475 6d70 hEX dUMP 0000: 2369 6e63 6c75 6465 203c 6373 7464 696f #INCLUDE <CSTDIO 0010: 3e > 0000: 7072 696e 7466 2822 4865 6c6c 6f2c 2057 PRINTF("hELLO, w 0010: 6f72 6c64 215c 6e22 293b ORLD!\N"); 0000: 6d61 696e 203d 2064 6f20 6765 744c 696e MAIN = DO GETlIN 0010: 6520 3e3e 3d20 7072 696e 7420 2e20 7375 E >>= PRINT . SU 0020: 6d20 2e20 6d61 7020 7265 6164 202e 2077 M . MAP READ . W 0030: 6f72 6473 ORDS
C语言格式化输出的时候用%x就自动输出成十六进制了。
#include<iostream> #include<cassert> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<string> #include<iterator> #include<cstdlib> #include<vector> #include<stack> #include<queue> #include<map> #include<set> using namespace std; #define debug(x) cout<<"debug "<<x<<endl; #define rep(i,f,t) for(int i = (f),_end_=(t); i <= _end_; ++i) #define rep2(i,f,t) for(int i = (f),_end_=(t); i < _end_; ++i) #define dep(i,f,t) for(int i = (f),_end_=(t); i >= _end_; --i) #define dep2(i,f,t) for(int i = (f),_end_=(t); i > _end_; --i) #define clr(c, x) memset(c, x, sizeof(c) ) typedef long long int64; const int INF = 0x5f5f5f5f; const double eps = 1e-8; //***************************************************** char str[5000]; int len; int col; void aline(int i){ int j = i+16; col = 0; for(; i<j && i<len; i+=2){ if(i+1<len){ printf("%02x%02x ",str[i],str[i+1]); }else{ printf("%02x ",str[i]); } col += 5; } while(col++ % 40)printf(" "); } void achar(char c){ if(c >= 'a' && c <= 'z')c = c-'a'+'A'; else if(c >= 'A' && c <= 'Z')c = c - 'A' + 'a'; printf("%c",c); } void output() { for(int i = 0; i < len; ){ printf("%04x: ",i); aline(i); for(int j = i+16; i < j&& i<len; ++i)achar(str[i]); printf("\n"); } } int main() { while(gets(str)){ len = strlen(str); output(); } return 0; }
相关文章推荐
- HDOJ4054 Hexadecimal View[编码题]
- Hdu 4054 Hexadecimal View
- hdu 4054 Hexadecimal View(字符串)
- hdu 4054 Hexadecimal View
- HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)
- HDU 4054 Hexadecimal View【模拟】【字符串处理】
- D - Hexadecimal View HDU - 4054(模拟)进制转换
- HDU 4054 Hexadecimal View(模拟)
- Hexadecimal View HDU 4054 简短代码 详解
- HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)
- 7/9 原型编码阶段: (6) 使用DetailsView和FormView(7-5 11:54)
- Android与webview JS 键值编码差异
- ZOJ 3542 Hexadecimal View [2011大连现场赛]
- 排球积分程序(六)——View的编码
- hdoj 2719 (url在传输过程中的编码)
- 更改TextView背景色——编码定义颜色
- 编码设置FrameLayout子View的layout_gravity,gravity
- HDOJ 4054 Hexadecimal View
- Android高效率编码-findViewById()的蜕变-注解,泛型,反射