题意:按要求输出。第一列是表示第几行。每行仅仅能有16个字节的字母,第二列是16进制的ASCII码。第三列大写和小写转换
思路:纯模拟,注意字母的十六进制是2位
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 5000; char str[MAXN]; int main() { while (cin.getline(str, 4100)) { int len = strlen(str); for (int t = 0; t < len ; t += 16) { printf("%04x: ", t); for (int i = t; i < t+16; i += 2) { if (i < len) printf("%02x", str[i]); else printf(" "); if (i+1 < len) printf("%02x", str[i+1]); else printf(" "); printf(" "); } for (int i = t; i < len && i < t+16; i++) { if (str[i] >= 'a' && str[i] <= 'z') printf("%c", str[i]-'a'+'A'); else if (str[i] >= 'A' && str[i] <= 'Z') printf("%c", str[i]-'A'+'a'); else printf("%c", str[i]); } printf(" "); } } return 0; }