1005
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.
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'.
Convert the input from EBCDIC to ASCII, and output it in the same format as the input.
C59340D7A2A840C3969587999696
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; }