题意 :
输出分三列。
第一列 : 0000: 表示当前语句的第1行 0010:表示当前语句的第二行。 以为规定一行只能输出16个字节, 所以代码中的一行可能要多行输出。 比如 该行代码一行有110字节 110 = 6 * 16 + 14就要输出 06e0:
第二列: 一个字节8位, 一个16进制的数 4位, 所以每两个 16进制数就代表一个字符。
不满16个字节,要输出空格。
第三列: 把代码的的大小写互换。 每16个就要换行, 输出完一行代码也要换行(后面无多余的空格)。
列与列之间有一个空格。
AC代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int N = 5000;
char buf[N];
int main() {
memset(buf, 0, sizeof(buf));
while(gets(buf)) {
int len = strlen(buf);
for(int i = 0; i < len; i += 16) {
printf("%04x: ", (int)i);
for(int j = i; j < i+16; j += 2) {
if(buf[j] == '\0') {
printf(" ");
}else {
printf("%x", (int)buf[j]);
}
if(buf[j+1] == '\0') {
printf(" ");
}else {
printf("%x ",(int)buf[j+1]);
}
}
for(int j = i; j < i+16 && j < len; j++) {
if(buf[j] >= 'a' && buf[j] <= 'z') {
putchar(toupper(buf[j]));
}else {
putchar(tolower(buf[j]));
}
}
puts("");
}
memset(buf, 0, sizeof(buf));
}
return 0;
}