您的位置:首页 > 其它

zju 3542 Hexadecimal View (大连现场赛水题)

2011-10-02 18:01 176 查看
一觉醒来,不觉已经是4点了,于是果断挑了一道水题。

View Code

#include<stdio.h>
#include<string.h>
#include <cctype>
char str[5000];
int main()
{
int i,j,k;
while(gets(str))
{
char s[]="0000";
int  len=strlen(str);
int row=len/16;
int left=len%16;
int a=0;
for(i=0;i<row;i++)
{
printf("%04x: ",a+i*16);
for(j=0;j<16;j++)
{
if((j+1)%2)
printf("%x",str[i*16+j]);
else printf("%x ",str[i*16+j]);
}
for(j=0;j<16;j++)
{
int t=i*16+j;
if( isupper(str[t]))
putchar(str[t]+32);
else  if( islower(str[t]))
putchar(str[t]-32);
else putchar(str[t]);
}
printf("\n");
}
if(left)
{
printf("%04x: ",a+i*16);
for(j=0;j<left;j++)
{
if((j+1)%2)
printf("%x",str[i*16+j]);
else printf("%x ",str[i*16+j]);
}
for(j=0;j<16-left;j++)
{
if(j%2)
printf("  ");
else printf("   ");
}
for(j=0;j<left;j++)
{
int t=i*16+j;
if( isupper(str[t]))
putchar(str[t]+32);
else  if( islower(str[t]))
putchar(str[t]-32);
else putchar(str[t]);
}
printf("\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: