模拟题,不说了
1
#include <stdio.h>
2
#include <string.h>
3
4
char buf[5000];
5
6
void Test()
7

{
8
int line = 0;
9
int len = strlen(buf);
10
int endLine = len/16;
11
int pos = 0;
12
for (int i = 0; i < endLine; ++i)
13
{
14
pos = i*16;
15
printf("%04x: ",pos);
16
for (int j = 0; j < 8; ++j)
17
{
18
printf("%x%x ",buf[pos+2*j],buf[pos+2*j+1]);
19
}
20
for (int j = 0; j < 16; ++j)
21
{
22
if (buf[pos+j] >= 'A' && buf[pos+j] <='Z')
23
{
24
printf("%c",buf[pos+j]-'A'+'a');
25
}
26
else if (buf[pos+j] >= 'a' && buf[pos+j] <='z')
27
{
28
printf("%c",buf[pos+j]-'a'+'A');
29
}
30
else
31
{
32
printf("%c",buf[pos+j]);
33
}
34
}
35
printf("\n");
36
}
37
pos = endLine*16;
38
if(pos < len)
39
{
40
printf("%04x: ",pos);
41
for (int j = 0; j < 16; ++j)
42
{
43
if(pos + j < len)
44
{
45
printf("%x",buf[pos+j]);
46
47
}
48
else
49
printf(" ");
50
if (j %2 == 1)
51
{
52
printf(" ");
53
}
54
}
55
for (int j = 0; j < 16; ++j)
56
{
57
if(pos + j < len)
58
{
59
60
if (buf[pos+j] >= 'A' && buf[pos+j] <='Z')
61
{
62
printf("%c",buf[pos+j]-'A'+'a');
63
}
64
else if (buf[pos+j] >= 'a' && buf[pos+j] <='z')
65
{
66
printf("%c",buf[pos+j]-'a'+'A');
67
}
68
else
69
{
70
printf("%c",buf[pos+j]);
71
}
72
}
73
}
74
printf("\n");
75
}
76
}
77
78
int main()
79

{
80
//freopen("data.txt","r",stdin);
81
//freopen("ans.txt","w",stdout);
82
while(gets(buf))
83
{
84
Test();
85
}
86
}
posted on 2012-03-26 10:42
bennycen 阅读(1086)
评论(0) 编辑 收藏 引用 所属分类:
算法题解