Problem:


博士が愛した符号

博士 : ピーター君、ついにやったよ。

ピーター : どうしました、デビッド博士？またくだらない発明ですか？

博士 : この表だよ、この表。

文字符号

（空白）101

'000000

,000011

-10010001

.010001

?000001

A100101

B10011010

文字符号

 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

ピーター : なんですか? この表は。

博士 : いいから、言う通りにしてみなさい。まず、お前の名前を紙に書いてごらん。

ピーター : はい"PETER POTTER" っと。

博士 : そうしたら、１文字ずつ、この表の「符号」に置き換えるのだよ。

ピーター : えーと"P" を「111」にして"E" を「110」して…結構面倒ですね。

111 110 00111 110 1000 101 111 00101 00111 00111 110 1000

           になりました。なんだか、バーコードみたいですね。

博士 : よろしい。そうしたら、置き換えた文字列を全部つなげて、５文字ごとに区切ってみなさい。

ピーター : はいはい、つなげて区切ると。

11111 00011 11101 00010 11110 01010 01110 01111 10100 0

           こんな感じになりました。けど、最後の「0」だけのやつはどうしますか?

博士 : ０を付け加えて５文字にしておいてくれ。

ピーター : えーと最後が０が1個だけだから０をあと４つ加えてやればいいんですね。できました。

11111 00011 11101 00010 11110 01010 01110 01111 10100 00000

博士 : 次はこの表を使うのだ。

符号文字

 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 ?

ピーター : これをどう使うんですか…そうか!今度は符号から文字に置き換えるのか!

博士 : そうそう。「11111」だったら「?」に、「00011」だったら「D」にとやってゆけばいいんだよ。

ピーター : これは単純ですね……えーと「?D-C'KOPUA」になりました。でも意味不明ですよ。

博士 : 文字数を数えてごらん。

ピーター : １０文字ですよ。あっ、「PETER POTTER」は１２文字だったのに２文字減っています。

博士 : そう、この表を使えば文字を減らすことができるのだよ。じゃあ今度はこの文章で同じことをやっ
       てごらん。

PETER PIPER PICKED A PECK OF PICKLED PEPPERS. A PECK OF PICKLED PEPPERS
PETER PIPER PICKED. IF PETER PIPER PICKED A PECK OF PICKLED PEPPERS, WHERE'S
THE PECK OF PICKLED PEPPERS PETER PIPER PICKED?

ピーター : ぎょぎょ、行が分かれていますが、どうするんですか?

博士 : 紙の都合で３行になってしまったが、改行文字のかわりに空白がある長い１行だと思っておくれ。

ピーター : はいはい。行と行の間にあるのは空白だと。しかし面倒だな……。

博士 : だったらプログラムにやらせればいいではないか。

ということで、ピーターの代わりに、読み込んだ文字列を符号に変換し出力するプログラムを作成してください。

入力

複数のデータセットが与えられます。各データセットに文字列１行（表に含まれる文字からなる）が与えられます。文字列に含まれる文字の数は 1 文字以上 100 文字以下です。

データセットの数は 200 を超えません。

出力

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

Sample Input

PETER POTTER

Output for the Sample Input

?D-C'KOPUA



Sample input:
PETER POTTER


Sample output:
?D-C'KOPUA

Submission status: Wrong Answer

Solution code:
encode = {
' ':'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'}

decode = {
'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':'?'}

while True:
	try:
		string = raw_input()
	except EOFError:
		break		

	# encode
	e, ans = "", ""
	for s in string:
		e += encode[s]
	tmp = []
	while len(e) > 4:
		tmp.append(e[0:5])
		e = e[5:]
	if len(e) != 0:
		e += '0' * (5 - len(e))
		tmp.append(e)
	print tmp

	# decode
	for s in tmp:
		ans += decode[s]
	print ans

Submission status: Wrong Answer

Solution code:
encode = {
' ':'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'}

decode = {
"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":"?"}

while True:
	try:
		string = raw_input()
	except EOFError:
		break		

	# encode
	e, ans = "", ""
	for s in string:
		e += encode[s]
	tmp = []
	while len(e) > 4:
		tmp.append(e[0:5])
		e = e[5:]
	if len(e) != 0:
		e += '0' * (5 - len(e))
		tmp.append(e)
	print tmp

	# decode
	for s in tmp:
		ans += decode[s]
	print ans

Submission status: Accepted

Solution code:
enc_s = " |'|,|-|.|?|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"
enc_i = "101|000000|000011|10010001|010001|000001|100101|10011010|0101|0001|110|01001|10011011|010000|0111|10011000|0110|00100|10011001|10011110|00101|111|10011111|1000|00110|00111|10011100|10011101|000010|10010010|10010011|10010000"
enc = dict(zip([i for i in enc_s.split("|")],[i for i in enc_i.split("|")]))
dec_s = "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| |.|,|-|'|?"
dec_i = "00000|00001|00010|00011|00100|00101|00110|00111|01000|01001|01010|01011|01100|01101|01110|01111|10000|10001|10010|10011|10100|10101|10110|10111|11000|11001|11010|11011|11100|11101|11110|11111"
dec = dict(zip([i for i in dec_i.split("|")],[i for i in dec_s.split("|")]))
def encode(a):
    return "".join([enc[i] for i in list(a)])
def decode(a):
    return "".join([dec[i] for i in a])

while(1):
    try:
        a = input()
        encoded = encode(a)
        l = len(encoded)%5
        l = 5 if l == 0 else l
        encoded = encoded + "0"*(5-l)
        l_ = int(len(encoded)/5)
        enc_list = [encoded[5*i:5*(i+1)] for i in range(l_)]
        decoded = decode(enc_list)
        print(decoded)
    except EOFError:
        break

Submission status: Accepted

Solution code:
encode={
" ":"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"
}
decode={
"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":"?"
}

def coding():
    code = ""
    stri = ""
    st = raw_input()
    for s in st:
        code += encode[s]
    if len(code)%5:
        code += "0"*(5-len(code)%5)
    b = 0
    while True:
        if b == len(code):
            return stri
        stri += decode[code[b:b+5]]
        b += 5
while True:
    try:
        print coding()
    except:
        break

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

k1 = {
" ":"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"}
import string
k2 = string.ascii_uppercase + " .,-'?"

for line in f:
    c1 = c2 = ''
    for c in line.rstrip('\n'):
        c1 += k1[c]

    #5の倍数に0フィル
    c1 += '0' * (- len(c1) % 5)

    for i in range(0, len(c1),5):
        c2 += k2[ int(c1[i:i + 5],2)]
    print(c2)

Submission status: Accepted

Solution code:
import sys

def suicide(sentence):
    string = ''
    for c in sentence:
        string += dic[c]
    lis = []
    while string:
        lis.append(string[:5])
        string = string[5:]
    for i in range(5-len(lis[-1])):
        lis[-1] = lis[-1] + '0'
    absolutely_fantastic(lis)
        
def absolutely_fantastic(lis):
    ans = ''
    for v in lis:
        a = 0
        for i in range(5):
            a += 2**(4-i)*int(v[i])
        else:
            ans += mathematics[a]
    else:
        print ans

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

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

if __name__ == '__main__':
    for line in sys.stdin:
        suicide(line.rstrip('\n'))

Submission status: Accepted

Solution code:
encode = {
" ":"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"
}
decode = {
"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":"?"
}
while True:
	try:
		list = raw_input()
	except EOFError:
		break
	code = ""
	for var in list:
		code += encode[var]
	
	if len(code) % 5 != 0:
		code += "0" * (5 - len(code) % 5)
	
	list = ""
	for i in range(0, len(code), 5):
		list += decode[code[i:i+5]]
	
	print list

Submission status: Accepted

Solution code:
d1 = {" ":"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",}
d2 = {"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":"?"}

while 1:
    try:
        c,dc='',''
        n=raw_input()
        for i in n:
            c+=d1[i]
        if len(c)%5!=0:
            c+='0'*(5-len(c)%5)
        for i in range(0,len(c),5):
            dc+=d2[c[i:i+5]]
        print dc
    except:
        break

Submission status: Accepted

Solution code:
import sys
d1 = {
' ':'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'
}

d2 = {
'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':'?'
}
for line in sys.stdin:
    s1 = ''
    s2 = ''
    for s in line.rstrip('\n'):
        s1 += d1[s]
    s1 += '0'*(-len(s1)%5)
    
    for i in range(len(s1)//5):
        s2 += d2[s1[i*5:(i+1)*5]]
        
    print(s2)

Submission status: Accepted

Solution code:
en=[chr(i) for i in range(65,91)]+list(' .,-\'?')
de={
' ':'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'
}
while 1:
    try:s=list(input())
    except:break
    a=b=''
    for x in s:a+=de[x]
    a+='0'*(-len(a)%5)
    for i in range(len(a)//5):
        b+=en[int(a[i*5:i*5+5],2)]
    print(b)

Submission status: Accepted

Solution code:
en=[chr(i) for i in range(65,91)]+list(' .,-\'?')
de={
' ':'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'
}
while 1:
    try:s=input()
    except:break
    a=b=''
    for x in s:a+=de[x]
    a+='0'*(-len(a)%5)
    for i in range(len(a)//5):b+=en[int(a[i*5:i*5+5],2)]
    print(b)

Submission status: Accepted

Solution code:
en='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+' .,-\'?' 
de={
' ':'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'
}
while 1:
    try:s=input()
    except:break
    a=b=''
    for x in s:a+=de[x]
    a+='0'*(-len(a)%5)
    for i in range(len(a)//5):b+=en[int(a[i*5:i*5+5],2)]
    print(b)

Submission status: Accepted

Solution code:
# Aizu Problem 0088: The Code A Doctor Loved
#
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'}

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


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)])


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

Submission status: Accepted

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

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


def main(args):
    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'
               }

    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':'?'
    }

    for line in sys.stdin:
        txt = line.strip('\n')
        ans = ''
        for c in txt:
            ans += encoder[c]

        if len(ans) % 5 != 0:
            ans += '0'*(5-len(ans)%5)

        # print(ans)

        result = ''
        while ans:
            temp = ans[:5]
            result += decoder[temp]
            ans = ans[5:]

        print(result)


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

Submission status: Accepted

Solution code:
import sys
d={' ':'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'}
for e in sys.stdin:
 a=''.join(d[c]for c in e[:-1])
 a+='0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(a[i:i+5],2)]for i in range(0,len(a),5)))

Submission status: Accepted

Solution code:
import sys
d={' ':'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'}
for e in sys.stdin:
 a=''.join(d[c]for c in e[:-1])
 a+='0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(a[i*5:i*5+5],2)]for i in range(len(a)//5)))

Submission status: Accepted

Solution code:
encode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + " .,-\'?"
decode = {" ":"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"}
while True:
    try:
        a = input()
        code = ""
        for inp in a:
            code += decode[inp]
        code += "0"*(-len(code)%5)
        ans = ""
        for i in range(len(code)//5):
            ans += encode[int(code[i*5:i*5 + 5], 2)]
        print(ans)
    except:
        break

Submission status: Accepted

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

dict1 = {"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"}

d1 = {v:k for k, v in dict1.items()}
d2 = {v:k for k, v in dict2.items()}


N = list(get_input())

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

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

    S3 = ""
    while S2 != "":
        if len(S2) >= 5:
            s = S2[0:5]
            S3 = S3 + d1[s]
            S2 = S2[5:]
        else:
            while len(S2) < 5:
                S2 = S2 + "0"
            S3 = S3 + d1[S2]
            break

    print(S3)

Submission status: Accepted

Solution code:
dic1 = {" ":"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"}

dic2 = {"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":"?"}

def to_digit(ss):
  ret = ""
  for s in ss:
    ret += dic1[s]
  return ret

def to_alpha(digit):
  ret = ""
  ind = 0
  end = len(digit)

  while ind + 5 < end:
    ret += dic2[digit[ind:ind + 5]]
    ind += 5

  if digit[ind:]:
    ret += dic2[digit[ind:] + "0" * (5 - end + ind)]

  return ret

while True:
  try:
    print(to_alpha(to_digit(input())))
  except EOFError:
    break

Submission status: Accepted

Solution code:
# AOJ 0088: The Code A Doctor Loved
# Python3 2018.6.28 bal4u

c2d = {'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", ' ':"101", "'":"000000", ',':"000011", \
'-':"10010001", '.':"010001", '?':"000001"}

d2c = ['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', ' ', '.', ',', '-',	'\'', '?']

while True:
	try: p = input()
	except: break
	ans, tmp = '', ''
	for c in p: tmp += c2d[c]
	if len(tmp) % 5 > 0: tmp += '0'*(5-len(tmp)%5)
	for i in range(0, len(tmp), 5): ans += d2c[int(tmp[i:i+5], 2)]
	print(ans)

Submission status: Accepted

Solution code:
d1={
" ":"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"}
d2={
"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":"?"}
while 1:
    try:
        s=raw_input()
    except EOFError:
        break
    s1,ans="",""
    for w in s:
        s1+=d1[w]
    if len(s1)%5!=0:
        s1+="0"*(5-len(s1)%5)
    for i in range(len(s1)/5):
        ans+=d2[s1[:5]]
        s1=s1[5:]
    print ans

Submission status: Accepted

Solution code:
enco1={" ":"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"}
enco2={"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":"?"}
while True:
    try:
        s="".join([enco1[w] for w in raw_input()])
        if not len(s)%5==0:s=s+"0"*(5-len(s)%5)
        print "".join([enco2[s[i:i+5]] for i in xrange(0,len(s),5)])
    except:
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
import io

d1 = {
    ' ': '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'
    }
d2 = {n: chr(n+ord('A')) for n in range(26)}
d2.update(zip(range(26, 32), " .,-'?"))

for line in stdin:
    stream = io.StringIO()
    stream.write(''.join(d1[c] for c in line.rstrip('\r\n')))
    stream.seek(0)
    c = stream.read(5)
    while c:
        print(d2[int(c.ljust(5, '0'), 2)], end='')
        c = stream.read(5)
    print()

Submission status: Accepted

Solution code:
conv1 = {' ':"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"}
conv2 = {"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":"?"}
while 1:
    try:
        s = raw_input()
        s1 = ""; s2 = "";
        for c in s:
            s1 += conv1[c]
        if len(s1)%5>0 :s1 += "0"*(5-(len(s1)%5))
        for i in xrange(len(s1)/5):
            s2 += conv2[s1[:5]]
            s1 = s1[5:]
        print s2
    except EOFError:
        break

Submission status: Accepted

Solution code:
conv1 = {' ':"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"}
conv2 = {"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":"?"}
while 1:
    try:
        s = raw_input()
        s1 = ""; s2 = "";
        for c in s:
            s1 += conv1[c]
        if len(s1)%5>0 :s1 += "0"*(5-(len(s1)%5))
        for i in xrange(0,len(s1),5):
            s2 += conv2[s1[i:i+5]]
        print s2
    except EOFError:
        break

Submission status: Accepted

Solution code:
dict1 = {" ":"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",}
dict2 = {"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":"?"}

while True:
	try:
		code,decode = "",""
		inp = raw_input()
		for alph in inp:
			code += dict1[alph]
		if len(code)%5 != 0:
			code += "0"*(5-len(code)%5)
		for i in range(0,len(code),5):
			decode += dict2[code[i:i+5]]
		print decode
	except:
		break