回答
Submission #419436 - DigitalArts プログラミングコンテスト2012 | AtCoder
パスワードのNGワードを渡すから,NGだったらすべて*マーク出力してください.って問題.
ちなみに*はワイルドカードなので,a*bはaabもabbもacbも全部,***.
試すケース数が少ないので,総当りで調べてもなんとかなる.
ngワードの長さと今調べるwordの長さを比べ,一致しているならば,1文字ずつ比べる.
それで違っている文字数を求める.あとでワイルドカードの*分は計算し直す.
で,違っている文字数が0の時,ngワードとして,置換処理を行う.
ちょっと逐次処理しすぎている感じがするので,もう少しうまく文字列を捌けないかなあと思いました.
あと変数名がダサい()
import copy words = [word for word in input().split()] N = int(input()) for _ in range(N): ng = input() ngl = len(ng) for j in range(len(words)): if len(words[j]) != ngl: continue ummatchidx = [] for i in range(ngl): if words[j][i] != ng[i]: ummatchidx.append(i) check = copy.deepcopy(ummatchidx) for i in range(len(ummatchidx)): if ng[ummatchidx[i]] == "*": check.remove(ummatchidx[i]) if len(check) == 0: words[j] = "*" * len(words[j]) print(" ".join(words))