Official
B - Wild Card Editorial
by
B - Wild Card Editorial
by
vwxyz
原案:vwxyz
\(S\) が \(T\) にマッチするならば、\(i=1,2,\dots,N\) について \(T_i\) は \(S_i\) か * のいずれかです。
逆にそれを満たすならば、\(S\) は \(T\) にマッチするので、それを判定すればよいです。
c++の実装例
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
string S,T;
cin>>S>>T;
string ans="Yes";
for(int i=0;i<N;i++){
if(T[i]!=S[i]&&T[i]!='*'){
ans="No";
}
}
cout<<ans<<"\n";
}
Pythonの実装例
N=int(input())
S=input()
T=input()
if all(t in s+"*" for s,t in zip(S,T)):
ans="Yes"
else:
ans="No"
print(ans)
posted:
last update:
