
Hexadecimal View

此题没有考查任何一个算法知识点,只是一道用来练代码熟悉度的题目
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <cstdio> #include <cstring> #include <string> #include <cctype> using namespace std; bool vis[4100]; int addr=0; int pos=0;int postmp=0; void (string& s) { int len=s.size(); for(int i=postmp;i<postmp+16&&i!=len;i++) { if(islower(s[i])) printf("%c",s[i]-('a'-'A')); else if(isupper(s[i])) printf("%c",s[i]+('a'-'A')); else printf("%c",s[i]); } printf("n"); } void row(string& s) { printf("%04x: ",addr); int idx=pos;int cnt=0;int cnt2=0; int len=s.size(); int col=0; postmp=pos; for(;cnt<16&&!vis[len-1];idx++) { printf("%02x",s[idx]);col+=2; vis[idx]=1; cnt2++;cnt++; if(cnt2==2) { printf(" ");col++; cnt2=0; } } for(int i=0;i<=39-col;i++) printf(" "); pos=idx; } int main() { string str; while(getline(cin,str)) { addr=0;pos=0; memset(vis,0,sizeof(vis)); int len=str.size(); for(;!vis[len-1];addr+=16) { row(str); conv(str); } str=""; } return 0; }
|
近期评论