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

一觉醒来,不觉已经是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");
}
}
}

你可能感兴趣的:(view)