http://acm.hdu.edu.cn/showproblem.php?pid=4054
貌似一般区域赛都会有一道水题
这道题PE了一次 因为输出每个数其实是两个位 如果用空格补齐的话 应该用两个空格 我用了一个空格,,,
学到:
1、%x 十六进制输出 可以输出整型,字符型等等
2、%02x 保证两位 而且会输出先导0的两位
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const double pi = acos(-1.0);
const int INF = 100000000;
const int MAXN = 4096 +200;
char s[MAXN];
int len;
char ch(char x)
{
if(x>='a' && x<='z')return x-32;
if(x>='A' && x<='Z')return x+32;
return x;
}
void solve()
{
int cnt;
for(int i=0;i<len;i+=16)
{
if(i%16 == 0)
printf("%04x:",i);
cnt=0;
for(int j=i;j<len && j<16+i;j+=2)
{
printf(" %02x",s[j]);
if(j+1>=len)printf(" ");
else printf("%02x",s[j+1]);
cnt+=2;
}
//putchar(' ');
int cc=0;
while(cnt<16)
{
//printf("%d%d%d%d%d",cc,cc,cc,cc,cc);
printf(" ");
cnt+=2;
}
putchar(' ');//putchar('|');
for(int j=i;j<len && j<16+i;j++)
putchar(ch(s[j]));
putchar('\n');
}
}
int main()
{
//IN("hdu4054.txt");
while(gets(s))
{
len=strlen(s);
solve();
}
return 0;
}