pat_BL_1014

2016_8_23
这题3条判断条件要搞对,注意第三条包括大写和小写字母,否则第四个样例过不了。。(没看清题目这里花了点时间)
ac code

# -*- coding: utf-8 -*-
"""
Created on Mon Aug 22 19:08:13 2016

@author: hanzy
"""

if __name__ == "__main__":
    date = ['MON','TUE','WED','THU','FRI','SAT','SUN']
    time = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N']    
    engl = ['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']    
    info1 = raw_input()
    info2 = raw_input()
    info3 = raw_input()
    info4 = raw_input()
    res = []
    count = 0
    a = range(len(info1)) if len(info1)<len(info2) else range(len(info2))
    b = range(len(info3)) if len(info3)<len(info4) else range(len(info4))
    for i in a:
        if count == 2:
            break
        if info1[i] == info2[i] and info1[i]>='A' and info1[i]<='G' and count == 0:
            res.append(date[engl.index(info1[i])]) 
            count += 1
        elif info1[i] == info2[i] and (info1[i]>='A' and info1[i]<='N' or info1[i]>='0' and info1[i]<='9') and count == 1:
            res.append(int(time.index(info1[i])))
            count += 1
    for i in b:
        if info3[i] == info4[i] and (info3[i]>='a' and info3[i]<='z' or info3[i]>='A' and info3[i]<='Z'):
            res.append(i)
            break

    print res[0] + ' ' + '%02d'%res[1] + ':' + '%02d'%res[2] 
brackets_temp = {'{{': '}}'} brackets_temp_and_link = {'{{': '}}', '[[': ']]'} def find_Bracket(str, brackets, p_start = 0): def find_left(str, brackets, pos_start): p1_result = len(str) for bl in iter(brackets): p1_this = str.find(bl, pos_start) if p1_this != -1 and p1_this < p1_result: p1_result = p1_this p2_result = p1_this + len(bl) br_result = bl if p1_result == len(str): return [-1] return [p1_result, p2_result, br_result] p0 = find_left(str, brackets, p_start) if p0[0] == -1: return [-1] nest = [brackets[p0[2]]] while len(nest) > 0: p0[2] = nest[-1] p1 = str.find(p0[2], p0[1]) if p1 == -1: return [-1] if len(p0[2]) == 0: raise Exception('Any bracket must not have zero length.') p2 = find_left(str, brackets, p0[1]) if p2[0] == -1: n = len(nest) - 1 while n > 0: p1 = str.find(nest[n - 1], p1 + len(nest[n])) if p1 == -1: return [-1] n -= 1 p0[1] = p1 + len(nest[0]) break else: if len(p2[2]) == 0: raise Exception('Any bracket must not have zero length.') if p2[0] < p1: nest.append(brackets[p2[2]]) p0[1] = p2[1] else: p0[1] = p1 + len(nest[-1]) del nest[-1] p0[2] = str[p0[0]:p0[1]] return p0 def gfind_Bracket(str, brackets): p0 = find_Bracket(str, brackets) while p0[0] != -1: yield p0 p0 = find_Bracket(str, brackets, p0[1]) def find_IgnoringBrackets(str, brackets, pat, init = 0, *args): p0 = str.find(pat, init, *args) if p0 == -1: return -1 p1 = find_Bracket(str, brackets) while p1[0] != -1 and p1[1] <= p0 + len(pat): p1 = find_Bracket(str, brackets, p1[1]) while p1[0] != -1 and p1[0] <= p0 + len(pat) - 1: p0 = str.find(pat, p1[1], *args) if p0 == -1: return -1 while p1[0] != -1 and p1[1] <= p0 + len(pat): p1 = find_Bracket(str, brackets, p1[1]) return p0 def gsplit_IgnoringBrackets(str, brackets, sep): if len(sep) > 0: p0 = 0 p1 = find_IgnoringBrackets(str, brackets, sep) while p1 != -1: yield str[p0:p1] p0 = p1 + len(sep) p1 = find_IgnoringBrackets(str, brackets, sep, p0) yield str[p0:] else: p0 = 0 for i in range(len(str)): if i == find_IgnoringBrackets(str, brackets, sep, i): if p0 < i: yield str[p0:i] yield str[i] p0 = i + 1 def parseTemp(str): if str[:2] != '{{' or str[-2:] != '}}': return None stri = str[2:-2] p_titleEnd = find_IgnoringBrackets(stri, brackets_temp_and_link, '|') if p_titleEnd == -1: return stri, {} args_result = {} count = 0 for arg in gsplit_IgnoringBrackets(stri[p_titleEnd + 1:], brackets_temp_and_link, '|'): p_eqsign = find_IgnoringBrackets(arg, brackets_temp_and_link, '=') if p_eqsign != -1: arg_name = arg[:p_eqsign] if arg_name.isdecimal() and arg_name.isascii(): arg_name = int(arg_name) if arg_name == 0: arg_name = '0' else: arg_name = arg_name.strip(' \x09\x0A\x0B\x0C\x0D') args_result[arg_name] = arg[p_eqsign + 1:].strip(' \x09\x0A\x0B\x0C\x0D') else: count += 1 args_result[count] = arg return stri[:p_titleEnd], args_result def iterNumArg(args): if len(args) > 0: def func_sort(k): return type(k) is int and k or 0 max_index = max(args, key = func_sort) if type(max_index) is int: for i in range(1, max_index + 1): if i in args: yield i, args[i] def glueTemp(title, args): result = [title] for i, v in iterNumArg(args): if i == len(result): result.append(v) else: result.append('{0}={1}'.format(i, v)) for k in iter(args): if type(k) is str: result.append('{0}={1}'.format(k, args[k])) return '{{{{{}}}}}'.format('|'.join(result)) import re def subTemp(pat, repl, str): result = [] p0 = 0 for p1, p2, t_temp in gfind_Bracket(str, brackets_temp): title, args = parseTemp(t_temp) if re.search(pat, title): result.append(str[p0:p1]) if callable(repl): result.append(glueTemp(*repl(title, args))) elif type(repl) is dict: result.append(glueTemp(title, repl)) else: result.append('{}'.format(repl)) p0 = p2 result.append(str[p0:]) return ''.join(result)
最新发布
08-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值