您的位置:首页 > 其它

hdu4690 EBCDIC

2015-08-19 16:08 323 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4690

EBCDIC

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


题意:

给你两个表,输入的是对应第一张表的坐标,求对应符合在第二张表格的坐标

坑点注意,不要用cin,cout,有时的偷懒会让你超时的!!!



(码的我也是好辛苦,特地来纪念一发~)

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define LL __int64
#define MOD 1000000007
const int INF = 0x3f3f3f3f;
string A[16][16]= {"NUL","SOH","STX","ETX","","HT","","DEL","","","","VT","FF","CR","SO","SI",
                   "DLE","DC1","DC2","DC3","","","BS","","CAN","EM","","","IFS","IGS","IRS","IUS ITB",
                   "","","","","","LF","ETB","ESC","","","","","","ENQ","ACK","BEL",
                   "","","SYN","","","","","EOT","","","","","DC4","NAK","","SUB",
                   "SP","","","","","","","","","","",".","<","(","+","|",
                   "&","","","","","","","","","","!","$","*",")",";","",
                   "-","/","","","","","","","","","",",","%","_",">","?",
                   "","","","","","","","","","`",":","#","@","'","=","""",
                   "","a","b","c","d","e","f","g","h","i","","","","","","",
                   "","j","k","l","m","n","o","p","q","r","","","","","","",
                   "","~","s","t","u","v","w","x","y","z","","","","","","",
                   "^","","","","","","","","","","[","]","","","","",
                   "{","A","B","C","D","E","F","G","H","I","","","","","","",
                   "}","J","K","L","M","N","O","P","Q","R","","","","","","",
                   "\\","","S","T","U","V","W","X","Y","Z","","","","","","",
                   "0","1","2","3","4","5","6","7","8","9","","","","","",""};

string B[8][16]= {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI",
                  "DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","IFS","IGS","IRS","IUS ITB",
                  "SP","!","""","#","$","%","&","'","(",")","*","+",",","-",".","/",
                  "0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?",
                  "@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
                  "P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_",
                  "`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
                  "p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL"};

//vector<int>q;
int main()
{
    char a,b;
    //string c;
    while(1)
    {
        a=getchar();
        if(a=='\n')break;
        b=getchar();
        int i,j,aa,bb;
        if(a>='A'&& a<='F')aa=a-'A'+10;
        if(a>='0'&& a<='9')aa=a-'0';
        if(b>='A'&& b<='F')bb=b-'A'+10;
        if(b>='0'&& b<='9')bb=b-'0';
        for(i=0; i<8; i++)
        {
            for(j=0; j<16; j++)
                if(B[i][j]==A[aa][bb])
                {
                    a=i+'0';
                    if(j>=0&&j<=9)
                        b=j+'0';
                    else
                        b=j-10+'A';
                    break;
                }
        }
       printf("%c%c",a,b);
    }
    printf("\n");
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: