Problem:


博士の暗号

博  士 : ?D-C'KOPUA

ピーター : どうしたんですか、デビッド博士? わけのわからないことを叫ぶのにはもう慣れましたが、
        今日は文章にすらなっていませんよ。

博  士 : ほれ。

ピーター : なんですか? この表は......ああ、予選の問題にこんなのがありました。表を使って文字を置き換え
       ると文字数が減るんですよね。まさか予選と本選で同じ問題を出して手を抜こうって気じゃないでし
       ょうね。

博  士 : 逆じゃよ。

ピーター : 逆? なるほど、今度は短くした文字列を元に戻そうって問題ですか。ということは「?D-C'KOPUA」の
      文字を、この表を使って「文字」から「符号」に置きかえるんですね......できましたよ。

11111 00011 11101 00010 11110 01010 01110 01111 10100 00000

博  士 : うむ。次はこれじゃ。

ピーター : そうそう、こんな表もありましたね。これを逆に使うんだから「符号」から「文字」に置き換えればいい
          んですね。でも、最初は「11111」ですが表にありませんよ?

博     士 : そういうときは、もっと短くするか、後ろとつなげるかしてみるのだよ。

ピ ー タ ー : じゃあ短くして......あ、 「111」ならあります。じゃあ最初は「P」ですね。そうすると残りは「11」ですが、
            これはぴったり合うのがないから次の「00011」から 1 文字借りて「110」にすればいいんですね。

博     士 : そうそう。つまり「E」だね。

ピ ー タ ー : それで残るのが「0011」なので、これも次から借りて「00111」にして「T」と......。全部できました。最
          後の「0000」は捨てちゃえばいいんですよね?

博     士 : そうじゃ、よろしい。次はこれじゃ。

?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI

博     士 : さらにこれじゃ。

?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ

博     士 : 仕上げにこうじゃ。

?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI

ピ ー タ ー : しっかし面倒だなあ。博士、今度は自分でプログラムを作って下さいよ。

  ということで、博士のかわりに、上の文章を置き換えるプログラムを作成してください。

Input

複数のデータセットが与えられます。各データセットとして、１つの文字列（表に含まれる文字からなる 200 文字以下の文字列）が１行に与えられます。入力の終わりまで処理してください。データセットの数は 200 を超えません。

Output

各データセットごとに、変換後の文字列を１行に出力してください。

Sample Input

?D-C'KOPUA

Output for the Sample Input

PETER POTTER



Sample input:
?D-C'KOPUA


Sample output:
PETER POTTER

Submission status: Accepted

Solution code:
#! python.exe
dic = {}
for idx, c in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"):
    dic[c] = str(format(idx,'b').zfill(5))

decode = {"101"      : " ", "0101"     : "C", "0110"     : "K", "00110"    : "S",
          "000000"   : "'", "0001"     : "D", "00100"    : "L", "00111"    : "T",
          "000011"   : ",", "110"      : "E", "10011001" : "M", "10011100" : "U",
          "10010001" : "-", "01001"    : "F", "10011110" : "N", "10011101" : "V",
          "010001"   : ".", "10011011" : "G", "00101"    : "O", "000010"   : "W",
          "000001"   : "?", "010000"   : "H", "111"      : "P", "10010010" : "X",
          "100101"   : "A", "0111"     : "I", "10011111" : "Q", "10010011" : "Y",
          "10011010" : "B", "10011000" : "J", "1000"     : "R", "10010000" : "Z"}
#print(dic)
while True:
    try:
        line = input()
    except:
        break
    s = ""
    for c in line:
        s += dic[c]
    ans = ""
    while len(s) > 5 or s.count("1") :
        for key in decode:
            n = len(key)
            if s[0:n] == key:
                ans += decode[key]
                s = s[n:]
                break
#        print(ans, s)
    print(ans)

Submission status: Accepted

Solution code:
#! python.exe
dic = {}
for idx, c in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"):
    dic[c] = str(format(idx,'b').zfill(5))

decode = {"101"      : " ", "0101"     : "C", "0110"     : "K", "00110"    : "S",
          "000000"   : "'", "0001"     : "D", "00100"    : "L", "00111"    : "T",
          "000011"   : ",", "110"      : "E", "10011001" : "M", "10011100" : "U",
          "10010001" : "-", "01001"    : "F", "10011110" : "N", "10011101" : "V",
          "010001"   : ".", "10011011" : "G", "00101"    : "O", "000010"   : "W",
          "000001"   : "?", "010000"   : "H", "111"      : "P", "10010010" : "X",
          "100101"   : "A", "0111"     : "I", "10011111" : "Q", "10010011" : "Y",
          "10011010" : "B", "10011000" : "J", "1000"     : "R", "10010000" : "Z"}
#print(dic)
while True:
    try:
        line = input()
    except:
        break
    s = ""
    for c in line:
        s += dic[c]
    ans = ""
    tmp = ""
    for c in s:
        tmp += c
        if tmp in decode:
            ans += decode[tmp]
            tmp = ''
#        print(ans, s)
    print(ans)

Submission status: Accepted

Solution code:
import sys

CharToSign = {
    "A": "00000", "B": "00001", "C": "00010", "D": "00011",
    "E": "00100", "F": "00101", "G": "00110", "H": "00111",
    "I": "01000", "J": "01001", "K": "01010", "L": "01011",
    "M": "01100", "N": "01101", "O": "01110", "P": "01111",
    "Q": "10000", "R": "10001", "S": "10010", "T": "10011",
    "U": "10100", "V": "10101", "W": "10110", "X": "10111",
    "Y": "11000", "Z": "11001", " ": "11010", ".": "11011",
    ",": "11100", "-": "11101", "'": "11110", "?": "11111",
}
SignToChar = {
    "101": " ", "000000": "'", "000011": ",", "10010001": "-",
    "010001": ".", "000001": "?", "100101": "A", "10011010": "B",
    "0101": "C", "0001": "D", "110": "E", "01001": "F",
    "10011011": "G", "010000": "H", "0111": "I", "10011000": "J",
    "0110": "K", "00100": "L", "10011001": "M", "10011110": "N",
    "00101": "O", "111": "P", "10011111": "Q", "1000": "R",
    "00110": "S", "00111": "T", "10011100": "U", "10011101": "V",
    "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z",
}

for line in sys.stdin:
    line = line[:-1]

    sign = []
    for char in line:
        convert = CharToSign[char]
        sign.append(convert)

    sign = "".join(sign)

    startIndex = 0
    endIndex = 3

    string = []

    length = len(sign)
    while endIndex <= length:

        part = sign[startIndex:endIndex]
        if part in SignToChar:
            convert = SignToChar[part]
            string.append(convert)
            startIndex = endIndex
            endIndex += 3
        else:
            endIndex += 1

    string = "".join(string)
    print(string)

Submission status: Accepted

Solution code:
import sys

CharToSign = {
    "A": "00000", "B": "00001", "C": "00010", "D": "00011",
    "E": "00100", "F": "00101", "G": "00110", "H": "00111",
    "I": "01000", "J": "01001", "K": "01010", "L": "01011",
    "M": "01100", "N": "01101", "O": "01110", "P": "01111",
    "Q": "10000", "R": "10001", "S": "10010", "T": "10011",
    "U": "10100", "V": "10101", "W": "10110", "X": "10111",
    "Y": "11000", "Z": "11001", " ": "11010", ".": "11011",
    ",": "11100", "-": "11101", "'": "11110", "?": "11111",
}
SignToChar = {
    "101": " ", "000000": "'", "000011": ",", "10010001": "-",
    "010001": ".", "000001": "?", "100101": "A", "10011010": "B",
    "0101": "C", "0001": "D", "110": "E", "01001": "F",
    "10011011": "G", "010000": "H", "0111": "I", "10011000": "J",
    "0110": "K", "00100": "L", "10011001": "M", "10011110": "N",
    "00101": "O", "111": "P", "10011111": "Q", "1000": "R",
    "00110": "S", "00111": "T", "10011100": "U", "10011101": "V",
    "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z",
}

for line in sys.stdin:
    line = line[:-1]

    sign = ""
    for char in line:
        sign += CharToSign[char]

    string = ""
    part = ""

    for item in sign:
        part += item

        if part in SignToChar:
            string += SignToChar[part]
            part = ""

    print(string)

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

dict = {"A":"00000",\
        "B":"00001",\
        "C":"00010",\
        "D":"00011",\
        "E":"00100",\
        "F":"00101",\
        "G":"00110", \
        "H":"00111", \
        "I":"01000", \
        "J":"01001", \
        "K":"01010", \
        "L":"01011", \
        "M":"01100", \
        "N":"01101", \
        "O":"01110", \
        "P":"01111", \
        "Q":"10000", \
        "R":"10001", \
        "S":"10010", \
        "T":"10011", \
        "U":"10100", \
        "V":"10101", \
        "W":"10110", \
        "X":"10111", \
        "Y":"11000", \
        "Z":"11001", \
        " ":"11010", \
        ".":"11011", \
        ",":"11100", \
        "-":"11101", \
        "'":"11110", \
        "?":"11111"}

dict2 = {"101":" ",\
         "000000":"'",\
         "000011":",", \
         "10010001":"-", \
         "010001":".",\
         "000001":"?",\
         "100101":"A",\
         "10011010":"B",\
         "0101":"C",\
         "0001":"D",\
         "110":"E",\
         "01001":"F",\
         "10011011":"G",\
         "010000":"H",\
         "0111":"I",\
         "10011000":"J",\
         "0110":"K",\
         "00100":"L",\
         "10011001":"M",\
         "10011110":"N",\
         "00101":"O",\
         "111":"P",\
         "10011111":"Q",\
         "1000":"R",\
         "00110":"S",\
         "00111":"T",\
         "10011100":"U",\
         "10011101":"V",\
         "000010":"W",\
         "10010010":"X",\
         "10010011":"Y",\
         "10010000":"Z"}

N = list(get_input())

for l in range(len(N)):
    S1 = N[l]
    S2 = ""

    for i in range(len(S1)):
        S2 = S2 + dict[S1[i]]

    S3 = ""
    while S2 != "":
        flag = False
        for i in range(3, len(S2)+1):
            s = S2[0:i]
            if s in dict2:
                S3 = S3 + dict2[s]
                S2 = S2[i:]
                flag = True
                break
        if flag == False:
            break

    print(S3)

Submission status: Accepted

Solution code:
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

d={"101":" ",
   "000000":"'",
   "000011":",",
   "10010001":"-",
   "010001":".",
   "000001":"?",
   "100101":"A",
   "10011010":"B",
   "0101":"C",
   "0001":"D",
   "110":"E",
   "01001":"F",
   "10011011":"G",
   "010000":"H",
   "0111":"I",
   "10011000":"J",
   "0110":"K",
   "00100":"L",
   "10011001":"M",
   "10011110":"N",
   "00101":"O",
   "111":"P",
   "10011111":"Q",
   "1000":"R",
   "00110":"S",
   "00111":"T",
   "10011100":"U",
   "10011101":"V",
   "000010":"W",
   "10010010":"X",
   "10010011":"Y",
   "10010000":"Z"
    }

sk=sorted(d.keys(),key=lambda x:len(x))   
for t in sys.stdin:
    cn=0
    st=""
    ta="".join([cv1(i) for i in t[:-1]])
    tmp=""
    for i in ta:
        tmp+=i
        if tmp in d:
            st+=d[tmp]
            tmp=""
    print(st)

Submission status: Accepted

Solution code:
def code(string):
  codemap = {'A': '00000', 'B': '00001', 'C': '00010', 'D': '00011', 'E': '00100', 'F': '00101', 'G': '00110', 'H': '00111', 'I': '01000', 'J': '01001', 'K': '01010', 'L': '01011', 'M': '01100', 'N': '01101', 'O': '01110', 'P': '01111', 'Q': '10000', 'R': '10001', 'S': '10010', 'T': '10011', 'U': '10100', 'V': '10101', 'W': '10110', 'X': '10111', 'Y': '11000', 'Z': '11001', ' ': '11010', '.': '11011', ',': '11100', '-': '11101', "'": '11110', '?': '11111'}
  chrs=list(string)
  for i in range(len(chrs)):
    chrs[i] = codemap[chrs[i]]
  return ("".join(chrs))

def dec1chr(string):
  decodemap = {'101': ' ', '000000': "'", '000011': ',', '10010001': '-', '010001': '.', '000001': '?', '100101': 'A', '10011010': 'B', '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F', '10011011': 'G', '010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L', '10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q', '1000': 'R', '00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V', '000010': 'W', '10010010': 'X', '10010011': 'Y', '10010000': 'Z'}
  for key in decodemap.keys():
    if string[0:len(key)] == key: return (decodemap[key],string[len(key):])
  return ("",string)

def decode(string):
  answer=""
  while True:
    chr, string = dec1chr(string)
    if chr=="": return answer
    else:
      answer += chr
    
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break
for ipt in inputs:
  print(decode(code(ipt)))

Submission status: Accepted

Solution code:
encode={' ': '11010', "'": '11110', '-': '11101', ',': '11100', '.': '11011', '\
?': '11111', 'A': '00000', 'C': '00010', 'B': '00001', 'E': '00100', 'D': '0001\
1', 'G': '00110', 'F': '00101', 'I': '01000', 'H': '00111', 'K': '01010', 'J': \
'01001', 'M': '01100', 'L': '01011', 'O': '01110', 'N': '01101', 'Q': '10000', \
'P': '01111', 'S': '10010', 'R': '10001', 'U': '10100', 'T': '10011', 'W': '101\
10', 'V': '10101', 'Y': '11000', 'X': '10111', 'Z': '11001'}

decode={"101":" ","000000":"'","000011":",","10010001":"-","010001":".","000001\
":"?","100101":"A","10011010":"B","0101":"C","0001":"D","110":"E","01001":"F","\
10011011":"G","010000":"H","0111":"I","10011000":"J","0110":"K","00100":"L","10\
011001":"M","10011110":"N","00101":"O","111":"P","10011111":"Q","1000":"R","001\
10":"S","00111":"T","10011100":"U","10011101":"V","000010":"W","10010010":"X","\
10010011":"Y","10010000":"Z"}

while True:
    try:
        s=raw_input()
    except EOFError:
        break
    L=[encode[c] for c in s]
    s="".join(L)
    i=0
    S=[]
    while i<len(s):
        for c in decode:
            if s[i:].startswith(c):
                S.append(decode[c])
                i+=len(c)
                break
        else:
            break
    print "".join(S)

Submission status: Accepted

Solution code:
tableA,tableB = {},{}
def main():
    make_table()
    while True:
        try:
            s = "".join(map(lambda c: tableA[c],raw_input()))
        except:
            break
        tmp,ans = "",""
        for c in s:
            tmp += c
            if tmp in tableB:
                ans += tableB[tmp]
                tmp = ""
        print ans
    
def make_table():
    global tableA,tableB
    tableA={
        "A":"00000",
        "B":"00001",
        "C":"00010",
        "D":"00011",
        "E":"00100",
        "F":"00101",
        "G":"00110",
        "H":"00111",
        "I":"01000",
        "J":"01001",
        "K":"01010",
        "L":"01011",
        "M":"01100",
        "N":"01101",
        "O":"01110",
        "P":"01111",
        "Q":"10000",
        "R":"10001",
        "S":"10010",
        "T":"10011",
        "U":"10100",
        "V":"10101",
        "W":"10110",
        "X":"10111", 
        "Y":"11000",
        "Z":"11001",
        " ":"11010",
        ".":"11011",
        ",":"11100",
        "-":"11101",
        "'":"11110",
        "?":"11111"}
    tableB ={
        "101":" ",
        "000000":"'",
        "000011":",",
        "10010001":"-",
        "010001":".",
        "000001":"?",
        "100101":"A",
        "10011010":"B",
        "0101":"C",
        "0001":"D",
        "110":"E",
        "01001":"F",
        "10011011":"G",
        "010000":"H",
        "0111":"I",
        "10011000":"J",
        "0110":"K",
        "00100":"L",
        "10011001":"M",
        "10011110":"N",
        "00101":"O",
        "111":"P",
        "10011111":"Q",
        "1000":"R",
        "00110":"S",
        "00111":"T",
        "10011100":"U",
        "10011101":"V",
        "000010":"W",
        "10010010":"X",
        "10010011":"Y",
        "10010000":"Z"}

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    tableA,tableB = make_table()
    while True:
        try:
            s = "".join(map(lambda c: tableA[c],raw_input()))
        except:
            break
        tmp,ans = "",""
        for c in s:
            tmp += c
            if tmp in tableB:
                ans += tableB[tmp]
                tmp = ""
        print ans
    
def make_table():
    tableA={
        "A":"00000",
        "B":"00001",
        "C":"00010",
        "D":"00011",
        "E":"00100",
        "F":"00101",
        "G":"00110",
        "H":"00111",
        "I":"01000",
        "J":"01001",
        "K":"01010",
        "L":"01011",
        "M":"01100",
        "N":"01101",
        "O":"01110",
        "P":"01111",
        "Q":"10000",
        "R":"10001",
        "S":"10010",
        "T":"10011",
        "U":"10100",
        "V":"10101",
        "W":"10110",
        "X":"10111", 
        "Y":"11000",
        "Z":"11001",
        " ":"11010",
        ".":"11011",
        ",":"11100",
        "-":"11101",
        "'":"11110",
        "?":"11111"}
    tableB ={
        "101":" ",
        "000000":"'",
        "000011":",",
        "10010001":"-",
        "010001":".",
        "000001":"?",
        "100101":"A",
        "10011010":"B",
        "0101":"C",
        "0001":"D",
        "110":"E",
        "01001":"F",
        "10011011":"G",
        "010000":"H",
        "0111":"I",
        "10011000":"J",
        "0110":"K",
        "00100":"L",
        "10011001":"M",
        "10011110":"N",
        "00101":"O",
        "111":"P",
        "10011111":"Q",
        "1000":"R",
        "00110":"S",
        "00111":"T",
        "10011100":"U",
        "10011101":"V",
        "000010":"W",
        "10010010":"X",
        "10010011":"Y",
        "10010000":"Z"}
    return tableA,tableB

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


code_table = {chr(65+i): '{:05b}'.format(i) for i in range(26)}
code_table.update({' ': '11010', '.': '11011', ',': '11100', '-': '11101',
                   "'": '11110', '?': '11111'})


def decrypt(it):
    if int(next(it)):
        if int(next(it)):
            if int(next(it)):
                return 'P'
            else:
                return 'E'
        else:
            if int(next(it)):
                return ' '
            else:
                if int(next(it)):
                    if int(next(it)):
                        if int(next(it)):
                            if int(next(it)):
                                if int(next(it)):
                                    return 'Q'
                                else:
                                    return 'N'
                            else:
                                if int(next(it)):
                                    return 'V'
                                else:
                                    return 'U'
                        else:
                            if int(next(it)):
                                if int(next(it)):
                                    return 'G'
                                else:
                                    return 'B'
                            else:
                                if int(next(it)):
                                    return 'M'
                                else:
                                    return 'J'
                    else:
                        if int(next(it)):
                            return 'A'
                        else:
                            if int(next(it)):
                                if int(next(it)):
                                    return 'Y'
                                else:
                                    return 'X'
                            else:
                                if int(next(it)):
                                    return '-'
                                else:
                                    return 'Z'
                else:
                    return 'R'
    else:
        if int(next(it)):
            if int(next(it)):
                if int(next(it)):
                    return 'I'
                else:
                    return 'K'
            else:
                if int(next(it)):
                    return 'C'
                else:
                    if int(next(it)):
                        return 'F'
                    else:
                        if int(next(it)):
                            return '.'
                        else:
                            return 'H'
        else:
            if int(next(it)):
                if int(next(it)):
                    if int(next(it)):
                        return 'T'
                    else:
                        return 'S'
                else:
                    if int(next(it)):
                        return 'O'
                    else:
                        return 'L'
            else:
                if int(next(it)):
                    return 'D'
                else:
                    if int(next(it)):
                        if int(next(it)):
                            return ','
                        else:
                            return 'W'
                    else:
                        if int(next(it)):
                            return '?'
                        else:
                            return "'"


def main():
    for line in stdin:
        it = iter(''.join(code_table[c] for c in line.rstrip('\r\n')))
        try:
            while 1:
                print(decrypt(it), end='')
        except StopIteration:
            print()
    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


code_table = {chr(65+i): '{:05b}'.format(i) for i in range(26)}
code_table.update({' ': '11010', '.': '11011', ',': '11100', '-': '11101',
                   "'": '11110', '?': '11111'})

decrypt = {
    '101': ' ', '000000': "'", '000011': ',', '10010001': '-',
    '010001': '.', '000001': '?', '100101': 'A', '10011010': 'B',
    '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F',
    '10011011': 'G', '010000': 'H', '0111': 'I', '10011000': 'J',
    '0110': 'K', '00100': 'L', '10011001': 'M', '10011110': 'N',
    '00101': 'O', '111': 'P', '10011111': 'Q', '1000': 'R',
    '00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V',
    '000010': 'W', '10010010': 'X', '10010011': 'Y', '10010000': 'Z'}


def main():
    for line in stdin:
        buf = ''
        for c in ''.join(code_table[c] for c in line.rstrip('\r\n')):
            buf += c
            plain = decrypt.get(buf)
            if plain:
                print(plain, end='')
                buf = ''
        print()
    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ctob={"A":"00000", "B":"00001", "C":"00010", "D":"00011", "E":"00100", "F":"00101", "G":"00110", "H":"00111", "I":"01000", "J":"01001", "K":"01010", "L":"01011", "M":"01100", "N":"01101", "O":"01110", "P":"01111", "Q":"10000", "R":"10001", "S":"10010", "T":"10011", "U":"10100", "V":"10101", "W":"10110", "X":"10111", "Y":"11000", "Z":"11001", " ":"11010", ".":"11011", ",":"11100", "-":"11101", "'":"11110", "?":"11111"}
btoc={'0110': 'K', '0111': 'I', '111': 'P', '110': 'E', '10011010': 'B', '10011011': 'G', '000011': ',', '000010': 'W', '10011111': 'Q', '10011110': 'N', '100101': 'A', '01001': 'F', '00111': 'T', '00110': 'S', '10010010': 'X', '0001': 'D', '0101': 'C', '10010000': 'Z', '10010001': '-', '101': ' ', '10011001': 'M', '10011000': 'J', '10011100': 'U', '10011101': 'V', '000000': "'", '000001': '?', '010001': '.', '010000': 'H', '10010011': 'Y', '00100': 'L', '00101': 'O', '1000': 'R'}

while 1:
	try:
		a=raw_input()
		b=""
		for w in a:
			b+=ctob[w]
		tmp,ans="",""
		for w in b:
			tmp+=w
			if tmp in btoc:
				ans+=btoc[tmp]
				tmp=""
		print ans
	except:
		break

Submission status: Accepted

Solution code:
en = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?"

de = {"101":" ","000000":"\'","000011":",","10010001":"-","010001":".","000001":"?",
          "100101":"A","10011010":"B","0101":"C","0001":"D","110":"E","01001":"F",
          "10011011":"G","010000":"H","0111":"I","10011000":"J","0110":"K","00100":"L",
          "10011001":"M","10011110":"N","00101":"O","111":"P","10011111":"Q","1000":"R",
          "00110":"S","00111":"T","10011100":"U","10011101":"V","000010":"W","10010010":"X",
          "10010011":"Y","10010000":"Z"}
while 1:
    try:
        s = input()
        c = ""
        for i in s:
            f = format(en.find(i), "05b")
            c += f
        ans = ""
        tmp = ""
        for i in c:
            tmp += i
            if tmp in de:
                ans += de[tmp]
                tmp = ""
        print(ans)
    except:
        break

Submission status: Accepted

Solution code:

L = { " ": "101",
      "'": "000000",
      ",": "000011",
      "-": "10010001",
      ".": "010001",
      "?": "000001",
      "A": "100101",
      "B": "10011010",
      "C": "0101",
      "D": "0001",
      "E": "110",
      "F": "01001",
      "G": "10011011",
      "H": "010000",
      "I": "0111",
      "J": "10011000",
      "K": "0110",
      "L": "00100",
      "M": "10011001",
      "N": "10011110",
      "O": "00101",
      "P": "111",
      "Q": "10011111",
      "R": "1000",
      "S": "00110",
      "T": "00111",
      "U": "10011100",
      "V": "10011101",
      "W": "000010",
      "X": "10010010",
      "Y": "10010011",
      "Z": "10010000" }

T = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"

de = dict()
for i in range(32):
    s = "{:05b}".format(i)
    ch = T[i]
    de[ch] = s

de2 = dict()
for k, v in L.items():
    de2[v] = k

while True:
    try:
        t = input()
    except:
        break
    codebit = ""
    for i in t:
        codebit += de[i]

    s = ""
    while True:
        if len(codebit) == 0:
            break
        if len(codebit) < 6 and int(codebit,2) == 0:
            break
        for k in range(3,9):
            if codebit[:k] in de2:
                s += de2[codebit[:k]]
                codebit = codebit[k:]
                break
    print(s)

Submission status: Accepted

Solution code:
to_bin = dict(zip([chr(i) for i in range(ord("A"), ord("Z") + 1)] + [" ", ".", ",", "-", "'", "?"],
                  [bin(i)[2:7].zfill(5) for i in range(2 ** 5)]))
to_chr = {"101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A",
          "10011010": "B",
          "0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I",
          "10011000": "J",
          "0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q",
          "1000": "R",
          "00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y",
          "10010000": "Z"}

while 1:
    try:
        N=list(input())
        first = ""
        for i in N:
           if i in to_bin:first +=to_bin[i]
        first = list(first)
        key=""
        answer = ""
        for j in first:
            key +=j
            if key in to_chr:
                answer +=to_chr[key]
                key = ""
        print(answer)
    except:break

Submission status: Accepted

Solution code:
encoder = {
    "A": "00000",
    "B": "00001",
    "C": "00010",
    "D": "00011",
    "E": "00100",
    "F": "00101",
    "G": "00110",
    "H": "00111",
    "I": "01000",
    "J": "01001",
    "K": "01010",
    "L": "01011",
    "M": "01100",
    "N": "01101",
    "O": "01110",
    "P": "01111",
    "Q": "10000",
    "R": "10001",
    "S": "10010",
    "T": "10011",
    "U": "10100",
    "V": "10101",
    "W": "10110",
    "X": "10111",
    "Y": "11000",
    "Z": "11001",
    " ": "11010",
    ".": "11011",
    ",": "11100",
    "-": "11101",
    "'": "11110",
    "?": "11111"
}
decoder={
    "101":" ",
    "000000":"'",
    "000011":",",
    "10010001":"-",
    "010001":".",
    "000001":"?",
    "100101":"A",
    "10011010":"B",
    "0101":"C",
    "0001":"D",
    "110":"E",
    "01001":"F",
    "10011011":"G",
    "010000":"H",
    "0111":"I",
    "10011000":"J",
    "0110":"K",
    "00100":"L",
    "10011001":"M",
    "10011110":"N",
    "00101":"O",
    "111":"P",
    "10011111":"Q",
    "1000":"R",
    "00110":"S",
    "00111":"T",
    "10011100":"U",
    "10011101":"V",
    "000010":"W",
    "10010010":"X",
    "10010011":"Y",
    "10010000":"Z"
}

def encode(strings):
    retval=""
    for s in strings:
        retval+=encoder[s]
    return retval

def decode(strings):
    for i in range(len(strings)+10):
        if strings[:i:] in decoder:
            return decoder[strings[:i:]]+decode(strings[i::])
    return ""


while True:
    try:
        print(decode(encode(input())))
    except EOFError:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        s=input()
        s_c=""
        c1=[" ",".",",","-","'","?"]
        for i in s:
            if 64<ord(i)<91:
                s_c+=str(bin(ord(i)-65)[2:]).zfill(5)
            else:
                s_c+=str(bin(c1.index(i)+26)[2:]).zfill(5)

        ch_3=["101","110","111"]
        re_3=[" ","E","P"]
        ch_4=["0101","0001","0111","0110","1000"]
        re_4=["C","D","I","K","R"]
        ch_5=["01001","00100","00101","00110","00111"]
        re_5=["F","L","O","S","T"]
        ch_6=["000000","000011","010001","000001","100101","010000","000010"]
        re_6=["'",",",".","?","A","H","W"]
        ch_8=["10010001","10011010","10011011","10011000","10011001","10011110","10011111","10011100","10011101","10010010","10010011","10010000"]
        re_8=["-","B","G","J","M","N","Q","U","V","X","Y","Z"]
        ans=""
        while 1:
            if len(s_c)==0 or len(s_c)<5 and int(s_c)==0:break
            elif s_c[:3] in ch_3:
                ans+=re_3[ch_3.index(s_c[:3])]
                s_c=s_c[3:]
            elif s_c[:4] in ch_4:
                ans+=re_4[ch_4.index(s_c[:4])]
                s_c=s_c[4:]
            elif s_c[:5] in ch_5:
                ans+=re_5[ch_5.index(s_c[:5])]
                s_c=s_c[5:]
            elif s_c[:6] in ch_6:
                ans+=re_6[ch_6.index(s_c[:6])]
                s_c=s_c[6:]
            elif s_c[:8] in ch_8:
                ans+=re_8[ch_8.index(s_c[:8])]
                s_c=s_c[8:]
            else:
                s_c+="0"
        print(ans)
    except:break

Submission status: Accepted

Solution code:
encode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + " .,-\'?"
decode = {"101":" ","000000":"\'","000011":",","10010001":"-","010001":".","000001":"?",
          "100101":"A","10011010":"B","0101":"C","0001":"D","110":"E","01001":"F",
          "10011011":"G","010000":"H","0111":"I","10011000":"J","0110":"K","00100":"L",
          "10011001":"M","10011110":"N","00101":"O","111":"P","10011111":"Q","1000":"R",
          "00110":"S","00111":"T","10011100":"U","10011101":"V","000010":"W","10010010":"X",
          "10010011":"Y","10010000":"Z"}
while True:
    try:
        s = input()
        code = ""
        for inp in s:
            code += format(encode.find(inp), "05b")
        ans = ""
        tmp = ""
        for inp in code:
            tmp += inp
            if tmp in decode:
                ans += decode[tmp]
                tmp = ""
        print(ans)
    except:
        break

Submission status: Accepted

Solution code:
to_bin = dict(zip([chr(i) for i in range(ord("A"), ord("Z") + 1)] + [" ", ".", ",", "-", "'", "?"],
                  [bin(i)[2:7].zfill(5) for i in range(2 ** 5)]))
to_chr = {"101":" ", "000000":"'", "000011":",", "10010001":"-", "010001":".", "000001":"?", "100101":"A", "10011010":"B",
          "0101":"C", "0001":"D", "110":"E", "01001":"F", "10011011":"G", "010000":"H", "0111":"I", "10011000":"J",
          "0110":"K", "00100":"L", "10011001":"M", "10011110":"N", "00101":"O", "111":"P", "10011111":"Q", "1000":"R",
          "00110":"S", "00111":"T", "10011100":"U", "10011101":"V", "000010":"W", "10010010":"X", "10010011":"Y", "10010000":"Z"}

while True:
  try:
    s = input()
  except EOFError:
    break
  bs = "".join([to_bin[c] for c in s])
  ans = ""
  while True:
    length = 9
    for i in range(length):
      if bs[:i] in to_chr:
        ans = ans + to_chr[bs[:i]]
        bs = bs[i:]
        break
    else:
      break
  print(ans)