HDU 4690 EBCDIC

Jimmy Carlson posted @ 2016年6月30日 00:22 in OI / CS , 377 阅读
2017 JCarlson Works All Rights Reserved
题目URL:http://acm.hdu.edu.cn/showproblem.php?pid=4690
类型:码农题
 
首先告诉你这是一台上古时期的计算机所使用的交换码表格,叫做 Extended Binary Coded Decimal Interchange Code (EBCDIC)。
现在给你一串EBCDIC串(HEX),你需要把它转成ASCII串(HEX)。
 
Sample Input
 
C59340D7A2A840C3969587999696
 

Sample Output
 
456C2050737920436F6E67726F6F
 
查表查的好累人啊……
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int chart[16][16]={{0,1,2,3,128,9,128,127,128,128,128,11,12,13,14,15},
		  {16,17,18,19,128,128,8,128,24,25,128,128,28,29,30,31},
		  {128,128,128,128,128,10,23,27,128,128,128,128,128,5,6,7},
		  {128,128,22,128,128,128,128,4,128,128,128,128,20,21,128,26},
		  {32,128,128,128,128,128,128,128,128,128,128,46,60,40,43,124},
		  {38,128,128,128,128,128,128,128,128,128,33,36,42,41,59,128},
		  {45,47,128,128,128,128,128,128,128,128,128,44,37,95,62,63},
		  {128,128,128,128,128,128,128,128,128,96,58,35,64,39,61,34},
		  {128,97,98,99,100,101,102,103,104,105,128,128,128,128,128,128},
		  {128,106,107,108,109,110,111,112,113,114,128,128,128,128,128,128},
		  {128,126,115,116,117,118,119,120,121,122,128,128,128,128,128,128},
		  {94,128,128,128,128,128,128,128,128,128,91,93,128,128,128,128},
		  {123,65,66,67,68,69,70,71,72,73,128,128,128,128,128,128},
		  {125,74,75,76,77,78,79,80,81,82,128,128,128,128,128,128},
		  {92,128,83,84,85,86,87,88,89,90,128,128,128,128,128,128},
		  {48,49,50,51,52,53,54,55,56,57,128,128,128,128,128,128}
};
void printhex(int absi){
	int r=absi/16; int s=absi%16;
	if (r<10) {cout<<r;} else {cout<<(char)(r+55);}
	if (s<10) {cout<<s;} else {cout<<(char)(s+55);}
}
int main(){
	char a,b; int c,d;
	while (true){
		a=getchar(); if (a=='\n') break; b=getchar();
		if (a>='0' && a<='9') {c=(int)a-48;} else {c=(int)a-55;}
		if (b>='0' && b<='9') {d=(int)b-48;} else {d=(int)b-55;}
		printhex(chart[c][d]);
	}
	cout<<endl;
	return 0;
}

不要吐槽我为什么不直接把chart搞成字符型的……我没想起来好了吧……

结果就是累死人= =

2017 JCarlson Works All Rights Reserved

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter