hdu 4690 EBCDIC(水)

582 篇文章 0 订阅

题目链接:hdu 4690 EBCDIC

代码

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
const int map[25][25] = {
    {0,1,2,3,0,9,0,127,0,0,0,11,12,13,14,15},
    {16,17,18,19,0,0,8,0,24,25,0,0,28,29,30,31},
    {0,0,0,0,0,10,23,27,0,0,0,0,0,5,6,7},
    {0,0,22,0,0,0,0,4,0,0,0,0,20,21,0,26},
    {32,0,0,0,0,0,0,0,0,0,0,46,60,40,43,124},
    {38,0,0,0,0,0,0,0,0,0,33,36,42,41,59,0},
    {45,47,0,0,0,0,0,0,0,0,0,44,37,95,62,63},
    {0,0,0,0,0,0,0,0,0,96,58,35,64,39,61,34},
    {0,97,98,99,100,101,102,103,104,105,0,0,0,0,0,0},
    {0,106,107,108,109,110,111,112,113,114,0,0,0,0,0,0},
    {0,126,115,116,117,118,119,120,121,122,0,0,0,0,0,0},
    {94,0,0,0,0,0,0,0,0,0,91,93,0,0,0,0},
    {123,65,66,67,68,69,70,71,72,73,0,0,0,0,0,0},
    {125,74,75,76,77,78,79,80,81,82,0,0,0,0,0,0},
    {92,0,83,84,85,86,87,88,89,90,0,0,0,0,0,0},
    {48,49,50,51,52,53,54,55,56,57,0,0,0,0,0,0},
};
const int maxn = 1e7 + 5;

char temp[17] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char str[maxn];

int main() {
    while(scanf("%s",str) == 1) {
        int len = strlen(str);
        for(int i = 0; i < len; i+=2) {
            int x,y;
            if(str[i] >= '0' && str[i] <= '9')
                x = str[i] - '0';
            else x = str[i] - 'A' + 10;

            if(str[i+1] >= '0' && str[i+1] <= '9')
                y = str[i+1] -'0';
            else y = str[i+1] - 'A' + 10;

            int d = map[x][y];
            int m = d / 16;
            int n = d % 16;
            printf("%c%c",temp[m],temp[n]);
        }
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值