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:
def two_ten(n):
    ans = ''
    while n:
        if n%2 == 0:
            ans += '0'
        else:
            ans += '1'
        n = n/2
    else:
        lis = list(ans)
        lis.reverse()
        return ''.join(lis).zfill(5)
    
def kawaii(lis):
    ans = []
    s = ''
    for v in lis:
        for c in v:
            s += c
            if s in dic:
                ans.append(dic[s])
                s = ''
    else:
        print ''.join(ans)

dic = {'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'}

mathematics = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 
               'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 
               'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23,
               'Y':24, 'Z':25, ' ':26, '.':27, ',':28, '-':29, "'":30, '?':31}

while True:
    try:
        lis = []
        for c in raw_input():
            lis.append(two_ten(mathematics[c]))
        else:
            kawaii(lis)
    except EOFError:
        break

Submission status: Accepted

Solution code:
def two_ten(n):
    ans = ''
    while n:
        if n%2 == 0:
            ans += '0'
        else:
            ans += '1'
        n = n/2
    else:
        lis = list(ans)
        lis.reverse()
        return ''.join(lis).zfill(5)
    
def kawaii(lis):
    ans = []
    s = ''
    for v in lis:
        for c in v:
            s += c
            if s in dic:
                ans.append(dic[s])
                s = ''
    else:
        print ''.join(ans)

dic = {'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'}

mathematics = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 
               'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 
               'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23,
               'Y':24, 'Z':25, ' ':26, '.':27, ',':28, '-':29, "'":30, '?':31,}

while True:
    try:
        lis = []
        for c in raw_input():
            lis.append(two_ten(mathematics[c]))
        else:
            kawaii(lis)
    except EOFError:
        break

Submission status: Accepted

Solution code:
sig = " .,-'?"
dic = {
    0b1101: " ",
    0b1000000: "'",
    0b1000011: ",",
    0b110010001: "-",
    0b1010001: ".",
    0b1000001: "?",
    0b1100101: "A",
    0b110011010: "B",
    0b10101: "C",
    0b10001: "D",
    0b1110: "E",
    0b101001: "F",
    0b110011011: "G",
    0b1010000: "H",
    0b10111: "I",
    0b110011000: "J",
    0b10110: "K",
    0b100100: "L",
    0b110011001: "M",
    0b110011110: "N",
    0b100101: "O",
    0b1111: "P",
    0b110011111: "Q",
    0b11000: "R",
    0b100110: "S",
    0b100111: "T",
    0b110011100: "U",
    0b110011101: "V",
    0b1000010: "W",
    0b110010010: "X",
    0b110010011: "Y",
    0b110010000: "Z",
}
while True:
    try:
        t = ""
        for c in raw_input():
            code = ord(c)
            if 65 <= code <= 90:
                t += format(code - 65, '05b')
            else:
                t += format(sig.index(c) + 26, '05b')
        q = 1
        ans = ""
        for e in t:
            q = (q<<1) + int(e)
            if dic.has_key(q):
                ans += dic[q]
                q = 1
        print ans
    except EOFError:
        break

Submission status: Accepted

Solution code:
def doc_string():
	"""
	I can fly.
	"""

encode = {
        "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"}
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:
		code = raw_input()
	except EOFError:
		break
	code0 = ""
	for var in code:
		code0 += encode[var]

	code = ""
	temp = ""
	for var in code0:
		temp += var
		if temp in decode:
			code += decode[temp]
			temp = ""
		
	print code

Submission status: Accepted

Solution code:
en=[chr(i) for i in range(65,91)]+list(' .,-\'?')
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()
    except:break
    a=b=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for i in range(len(a)):
        b+=a[i]
        if b in de:print(de[b],end='');b=''
    print()

Submission status: Accepted

Solution code:
en=[chr(i) for i in range(65,91)]+list(' .,-\'?') 
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()
    except:break
    a=b=c=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for i in range(len(a)):
        b+=a[i]
        if b in de:c+=de[b];b=''
    print(c)

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()
    except:break
    a=b=c=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for i in range(len(a)):
        b+=a[i]
        if b in de:c+=de[b];b=''
    print(c)

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()
    except:break
    a=b=c=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for x in a:
        b+=x
        if b in de:c+=de[b];b=''
    print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

# copy of cima code
# to confirm system is working correctly

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()
    except:break
    a=b=c=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for x in a:
        b+=x
        if b in de:c+=de[b];b=''
    print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    # encode
    # lst = []
    # for c in s:
    #     lst.append(tableA[c])
    # s = ''.join(lst)

    en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
    a = b = c = ''
    for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
    s = a

    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'
    }
    for x in a:
        b += x
        if b in de: c += de[b];b = ''
    return c

    # tmp, ans = '', ''
    # for c in s:
    #     tmp += c
    #     if tmp in tableB:
    #         ans += tableB[tmp]
    #         tmp = ''
    # return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    # encode
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    # en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
    a = b = c = ''
    # for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
    # s = a
    a = s

    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'
    }
    for x in a:
        b += x
        if b in de: c += de[b];b = ''
    return c

    # tmp, ans = '', ''
    # for c in s:
    #     tmp += c
    #     if tmp in tableB:
    #         ans += tableB[tmp]
    #         tmp = ''
    # return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    # encode
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    # en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
    a = b = c = ''
    # for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
    # s = a
    a = s

    # 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'
    # }
    # for x in a:
    #     b += x
    #     if b in de: c += de[b];b = ''
    # return c

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    s = s.strip('\n')
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    s = s.strip('\n')
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

for s in sys.stdin:
    s = s.strip('\n')
    #if s == '':
    #    break

    print(my_solve(s))
# while True:
#     try:
#         s = input()
#     except:
#         break
#
#     print(my_solve(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

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"}

def my_solve(s):
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

for s in sys.stdin:
    s = s.strip('\n')

    #if s == '':
    #    break

    print(my_solve(s))

Submission status: Accepted

Solution code:
import string
s = {i : "{:05b}".format(c) for i, c in zip(string.ascii_uppercase+" .,-'?", range(32))}
code = {'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:
        data = input()
    except:
        break
    d = ''.join(s[c] for c in data)
    ans=tmp=""
    for c in d:
        tmp += c
        if tmp in code:
            ans += code[tmp]
            tmp = ""
    print(ans)

Submission status: Accepted

Solution code:
# Aizu Problem 0111: Doctor's Memorable Code
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def bin5(k):
    b = bin(k)[2:]
    while len(b) < 5:
        b = '0' + b
    return b


CODE1 = {' ': '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'}
CODE1_rev = {value: key for key, value in CODE1.items()}

CODE2 = {bin5(k): chr(65+k) for k in range(26)}
symbols = [' ', '.', ',', '-', "'", '?']
for k in range(len(symbols)):
    CODE2[bin5(26+k)] = symbols[k]
CODE2_rev = {value: key for key, value in CODE2.items()}


def encode(string):
    enc = ''.join([CODE1[char] for char in string])
    while len(enc) % 5 != 0:
        enc += '0'
    return ''.join([CODE2[enc[5*k:5*k+5]] for k in range(len(enc) // 5)])

def decode(string):
    bitstring = ''.join([CODE2_rev[char] for char in string])
    decoded = ""
    while len(bitstring) > 0:
        k = 0
        while True:
            k += 1
            cand = bitstring[:k]
            if cand in CODE1_rev:
                decoded += CODE1_rev[cand]
                bitstring = bitstring[k:]
                break
            if k >= len(bitstring):
                return decoded
    return decoded


for line in sys.stdin:
    print(decode(line.replace('\n', '')))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0111


"""
import sys
from sys import stdin
input = stdin.readline


def solve(data):
    # AOJ 0088?????????
    encoder = {' ':'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'
               }
    rev_encoder = dict(zip(encoder.values(), encoder.keys()))

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


    txt = ''
    for d in data:
        txt += rev_decoder[d]

    result = ''
    while txt:
        match = False
        for k in rev_encoder.keys():
            if txt.startswith(k):
                match = True
                temp = rev_encoder[k]
                txt = txt[len(k):]
                result += temp
                break
        if match is False:
            break
    return result


def main(args):
    for data in sys.stdin:
        # data = "?D-C'KOPUA"
        result = solve(data.strip('\n'))
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0111

"""
import sys
from sys import stdin
input = stdin.readline


def solve(data):
    txt = ''
    for d in data:
        txt += rev_decoder[d]

    result = ''
    while txt:
        match = False
        for k in rev_encoder.keys():
            if txt.startswith(k):
                match = True
                result += rev_encoder[k]
                txt = txt[len(k):]
                break
        if match is False:
            break
    return result


# AOJ 0088?????????
encoder = {' ':'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'
}
rev_encoder = dict(zip(encoder.values(), encoder.keys()))

decoder = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F', '00110':'G', '00111':'H',
               '01000':'I', '01001':'J', '01010':'K', '01011':'L', '01100':'M', '01101':'N', '01110':'O', '01111':'P',
               '10000':'Q', '10001':'R', '10010':'S', '10011':'T', '10100':'U', '10101':'V', '10110':'W', '10111':'X',
               '11000':'Y', '11001':'Z', '11010':' ', '11011':'.', '11100':',', '11101':'-', '11110':"'", '11111':'?'
}
rev_decoder = dict(zip(decoder.values(), decoder.keys()))
def main(args):
    for data in sys.stdin:
        result = solve(data.strip('\n'))
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])