题解 | #字符串通配符# 把c的写法抄过来改造了一下
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
def compare(p, s): lp = len(p) ls = len(s) i = 0 j = 0 while i < lp and j < ls: if p[i] == s[j] or p[i] == "?" and s[j].isalnum(): i += 1 j += 1 elif p[i] == "*": # 合并** while p[i] == "*": if i + 1 == lp: return True else: i += 1 for k in range(j, ls): if compare(p[i:], s[k:]): return True return False # 三种情况 匹配0个字符 匹配下一个字符,匹配多个(std不动,还是*在匹配,str下移) # return compare(p[i:],s[j:]) or compare(p[i:],s[j+1:]) or compare(p[i:],s[j+1:]) else: return False if i == lp and j == ls: return True else: return False p = input().lower() s = input().lower() out = "true" if compare(p, s) else "false" print(out)