HDU 4690 EBCDIC
EBCDIC
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 169 Accepted Submission(s): 87
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.![](http://acm.hdu.edu.cn/data/images/C463-1005-1.jpg)
Here is the ASCII table.![](http://acm.hdu.edu.cn/data/images/C463-1005-2.jpg)
![](http://acm.hdu.edu.cn/data/images/C463-1005-1.jpg)
![](http://acm.hdu.edu.cn/data/images/C463-1005-2.jpg)
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
Hint
E.html download 方便图中文字复制
http://pan.baidu.com/share/link?shareid=453447595&uk=352484775
Author
Zejun Wu (watashi)
Source
多校第九场了,今天唯一过的一道题(别再唯一了好吗T_T)。。。
就是把上面表格中字符的标号对应到下面的标号上去,毫无难度的签道题,就是写起来费点事
另外注意某些字符在C/C++中的表示,比如'\\','\?','\"','\''等
还有就是那些不可打印的字符,我用了#define的方法把它们处理掉了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 3 #define NUL 0x0 4 #define SOH 0x1 5 #define STX 0x2 6 #define ETX 0x3 7 #define EOT 0x4 8 #define ENQ 0x5 9 #define ACK 0x6 10 #define BEL 0x7 11 #define BS 0x8 12 #define HT 0x9 13 #define LF 0xA 14 #define VT 0xB 15 #define FF 0xC 16 #define CR 0xD 17 #define SO 0xE 18 #define SI 0xF 19 #define DLE 0x10 20 #define DC1 0x11 21 #define DC2 0x12 22 #define DC3 0x13 23 #define DC4 0x14 24 #define NAK 0x15 25 #define SYN 0x16 26 #define ETB 0x17 27 #define CAN 0x18 28 #define EM 0x19 29 #define SUB 0x1A 30 #define ESC 0x1B 31 #define IFS 0x1C 32 #define IGS 0x1D 33 #define IRS 0x1E 34 #define IUS_ITB 0x1F 35 #define SP 0x20 36 #define DEL 0x7F 37 38 const char c[16][16]={{NUL ,SOH ,STX ,ETX ,'\0', HT ,'\0',DEL ,'\0','\0','\0', VT , FF , CR , SO , SI }, 39 {DLE ,DC1 ,DC2 ,DC3 ,'\0','\0', BS ,'\0',CAN , EM ,'\0','\0',IFS ,IGS ,IRS ,IUS_ITB}, 40 {'\0','\0','\0','\0','\0', LF ,ETB ,ESC ,'\0','\0','\0','\0','\0',ENQ ,ACK ,BEL}, 41 {'\0','\0',SYN ,'\0','\0','\0','\0',EOT ,'\0','\0','\0','\0',DC4 ,NAK ,'\0',SUB}, 42 { SP ,'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','.' ,'<' ,'(' ,'+' ,'|'}, 43 {'&' ,'\0','\0','\0','\0','\0','\0','\0','\0','\0','!' ,'$' ,'*' ,')' ,';' ,'\0'}, 44 {'-' ,'/' ,'\0','\0','\0','\0','\0','\0','\0','\0','\0',',' ,'%' ,'_' ,'>' ,'\?'}, 45 {'\0','\0','\0','\0','\0','\0','\0','\0','\0','`' ,':' ,'#' ,'@' ,'\'','=' ,'\"'}, 46 {'\0','a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'\0','\0','\0','\0','\0','\0'}, 47 {'\0','j' ,'k' ,'l' ,'m' ,'n' ,'o' ,'p' ,'q' ,'r' ,'\0','\0','\0','\0','\0','\0'}, 48 {'\0','~' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z' ,'\0','\0','\0','\0','\0','\0'}, 49 {'^' ,'\0','\0','\0','\0','\0','\0','\0','\0','\0','[' ,']' ,'\0','\0','\0','\0'}, 50 {'{' ,'A' ,'B' ,'C' ,'D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'\0','\0','\0','\0','\0','\0'}, 51 {'}' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'\0','\0','\0','\0','\0','\0'}, 52 {'\\','\0','S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y' ,'Z' ,'\0','\0','\0','\0','\0','\0'}, 53 {'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'\0','\0','\0','\0','\0','\0'}}; 54 55 56 int main() 57 { 58 char a,b; 59 60 while(1) 61 { 62 a=getchar(); 63 if(a=='\n') 64 break; 65 b=getchar(); 66 if(a>='0'&&a<='9') 67 { 68 if(b>='0'&&b<='9') 69 printf("%02X",c[a-'0'][b-'0']); 70 else if(b>='A'&&b<='F') 71 printf("%02X",c[a-'0'][b-'A'+10]); 72 } 73 else if(a>='A'&&a<='F') 74 { 75 if(b>='0'&&b<='9') 76 printf("%02X",c[a-'A'+10][b-'0']); 77 else if(b>='A'&&b<='F') 78 printf("%02X",c[a-'A'+10][b-'A'+10]); 79 } 80 } 81 printf("\n"); 82 83 return 0; 84 }