栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Detective-Geek

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/294227.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号