大连赛区现场赛最水的一题吧,没什么好说的,简单的模拟题,对于每一行内容,每次取16个字符出来进行处理,输出分成三部分处理会清晰一点。稍微注意下细节就是了
代码写的比较丑,大牛们就飞过吧~
#include <string>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;
string s;
int tot;
void print_x(string s1)
{
int cnt = 0;
for (int i=0; i<s1.length(); i++)
{
printf("%02x", int(s1[i]));
cnt++;
if (!(cnt&1)) printf(" ");
}
while (cnt < 16)
{
printf(" ");
cnt++;
if (!(cnt&1)) printf(" ");
}
}
void print_s(string s1)
{
for (int i=0; i<s1.length(); i++)
if (isalpha(s1[i]))
{
if (isupper(s1[i])) printf("%c", tolower(s1[i]));
else printf("%c", toupper(s1[i]));
}
else printf("%c", s1[i]);
printf("\n");
}
int main()
{
string st;
while (getline(cin, s))
{
tot = 0;
while (s != "")
{
printf("%04x: ", tot);
if (s.length() >= 16)
{
st = s.substr(0, 16);
s.erase(0, 16);
}
else
{
st = s;
s.clear();
}
print_x(st);
print_s(st);
tot+=16;
}
}
return 0;
}