杭电多校联赛<9>

1005

EBCDIC

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 51    Accepted Submission(s): 10


Problem Description
  
  
A mad scientist found an ancient message from an obsolete IBN System/360 mainframe. He believes that this message contains some very important secret about the Stein's Windows Project. The IBN System/360 mainframe uses Extended Binary Coded Decimal Interchange Code (EBCDIC). But his Artificial Intelligence Personal Computer (AIPC) only supports American Standard Code for Information Interchange (ASCII). To read the message, the mad scientist ask you, his assistant, to convert it from EBCDIC to ASCII. Here is the EBCDIC table.
       Here is the ASCII table.
 

Input
  
  
The input of this problem is a line of uppercase hexadecimal string of even length. Every two hexadecimal digits stands for a character in EBCDIC, for example, "88" stands for 'h'.
 

Output
  
  
Convert the input from EBCDIC to ASCII, and output it in the same format as the input.
 

Sample Input
  
  
C59340D7A2A840C3969587999696
 

Sample Output
  
  
456C2050737920436F6E67726F6F

解析:

两张表要对应起来的方法就是第一张表里面字符的位置和第二章表里面字符的位置,然后打表存储(第一张表里面的字符分别对应第二张表里面字符的位置)


代码如下:(16进制)

#include <cstdio>

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

int main() {
	int ord;
	while (scanf("%2X", &ord) != EOF) {
		printf("%02X", table[ord]);
	}
	puts("");
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值