题解 | #字符串通配符#

字符串通配符

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








全部评论

相关推荐

09-08 17:17
同济大学 Java
狗不理fe:里面的人劝一句,别来虾,我们部门24校招生淘汰率30%,还有一些人说有一年保护期,不可能!!!
我的秋招日记
点赞 评论 收藏
分享
夏日狂想曲:连体婴是这样的,不过国内还有上四休三的公司?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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