Detective-Geek

Detective Geek has a superpower of knowing when and where a crime is going to happen; unfortunately his superpower is encrypted, and he takes a lot of time decrypting it.
Everytime he sees a crime using his superpower he starts writing on paper and the result looks like this:

#*######*#*

mayjul sepsep octapr octsep sepjun octjan

As he is the one and only detective geek he wanted to write a program to help him decrypt faster.

The first line represents binary: #*######*#* becomes 10111111010
This equals the decimal number 1530, which means the time when the crime is going to happen is 15:30.

The second line encodes the address where the crime will take place. Every word in the encrypted address represents a character in the real address.
A word such as octapr can be split into two strings of length 3 oct and apr which are abbreviations for months october and april.
Each month represents a number according to its order in the year. “jan” = 0, “feb”= 1 ,“mar”= 2 … “dec” = 11
The string of two months represents a two-digit base 12 number. So octapr is 93
93 in base 12 becomes 111 in decimal
and the final step is to look in ascci table to see what letter correspond to 111.
so octapr -> "o"


Input
line 1 : time string representing the time
line 2 : address string representing the address
Output
line 1 : time in hh:mm format
line 2 : decrypted address


Constraints
date : contains only # and * ,1<=length<13, represents a valid 24-hr time.
adress : 5<=length<100, decodes to printable ASCII characters.
Example

Input
########*
mayjul sepsep octapr octsep sepjun octjan
Output
15:30
6hotel

解决方案:

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

time = input()
address = input()

bins = { '*':0, '#':1 }
months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']

# def duo2chr(duo):
#     dec = 0
#     count = 0
#     while int(duo) > 0:
#         bit = duo%10
#         duo = int(duo/10)
#         dec += bit*12**count
#         count += 1
#     return chr(dec)

def duo2chr(duo1, duo2):
    return chr(duo1*12 + duo2)

"""
Decrypt puzzles
"""
bin_str = ''
for i in time:
    bin_str += str(bins[i])
decrypt = int(bin_str, 2)

h = str(int(decrypt/100))
h = '0'+h if len(h) == 1 else h
m = str(int(decrypt%100))
time = h + ':' + m

address = address.split(' ')
addrs = [[i[j:j+3], i[j+3:j+6]] for j in range(0, len(i), 3) for i in address]

address = ''
for i in addrs:
    address += duo2chr(months.index(i[0]), months.index(i[1]))

print(time)
print(address)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值