The 2011 ACM-ICPC Asia Dalian Regional Contest——D Hexadecimal View

写得好挫,大牛们鄙视吧~

#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <time.h>
#include <cstdio>
#include <ctype.h>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define N 5000
#define FRE freopen("a.txt","r",stdin)
#define PI acos(-1.0)
#define MAX INT_MAX
#define MIN INT_MIN

char str[N];
int main(){
    while(gets(str)){
        int i,j;
        int len = strlen(str);
        if(!len)break;
        int add=0;
        printf("0000: ");
        char s[20];
        int cnt=0;
        int n=6;
        for(i=0;i<len;i++){

            if(isupper(str[i]))s[cnt++]=tolower(str[i]);
            else
            if(islower(str[i]))s[cnt++]=toupper(str[i]);
            else
            s[cnt++]=str[i];
            printf("%x",str[i]);
            n+=2;
            if(i%2){
                printf(" ");
                n++;
            }
            if((i+1)%16==0 &&i){
                s[cnt]='\0';
                printf("%s\n",s);
                if(i+1!=len){
                    printf("%04x: ",i+1);
                }
                cnt=0;
                n=6;
            }
        }
        if(len<16){
            for(i=n;i<46;i++)printf(" ");
            s[cnt]='\0';
            printf("%s\n",s);
        }
        if(len>=16 && len%16){
            for(j=n;j<46;j++)printf(" ");
            for(i=len-len%16;i<len;i++){
                char c;
                if(isupper(str[i]))c=tolower(str[i]);
                else
                if(islower(str[i]))c=toupper(str[i]);
                else
                c=str[i];
                printf("%c",c);
            }
            puts("");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值