题解 | #字符串通配符#

字符串通配符

https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036

import sys


s0, s1, *_, = sys.stdin.read().split()
s0, s1 = s0.lower(), s1.lower()
p0, p1 = 0, 0

c = None

while True:
    if p0>=len(s0) or p1>=len(s1):
        if p0==len(s0) and p1==len(s1): break
        if None is c: break
        (s, p0, p1) = c
        s += 1
        c = (s, p0, p1)
        p0+=1
        p1+=s
        if p1>=len(s1): break
        # print("abc", p0, p1, s0[p0], s1[p1], c, s)
        continue

    # print(p0, p1, s0[p0], s1[p1], c)

    a = ord(s1[p1])
    if (a<ord('a') or a>ord('z')) and s1[p1] not in '12.': print("false"); exit()

    if s0[p0] == s1[p1] or '?' == s0[p0]:
        p0+=1
        p1+=1
        continue

    if '*' == s0[p0]:
        s = 0
        c = (s, p0, p1)
        p0+=1
        p1+=s
        continue

    if None is not c:
        (s, p0, p1) = c
        s += 1
        c = (s, p0, p1)
        p0+=1
        p1+=s
        continue

    print("false"); exit()


if p0==len(s0) and p1==len(s1):
    print("true")
else:
    print("false")








全部评论

相关推荐

11-04 10:30
已编辑
门头沟学院 研发工程师
开心小狗🐶:“直接说答案”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务