D - Match or Not
D - Match or Not
https://atcoder.jp/contests/abc287/tasks/abc287_d
思路
https://www.acwing.com/solution/content/166180/
对于t,分成两个段,
前段在s和t的最大前缀找,
后端在s和t的最大后缀找。
Code
https://atcoder.jp/contests/abc287/submissions/38576945
string s, t; int main() { cin >> s; cin >> t; int slen = s.size(); int tlen = t.size(); int prefixlen = 0; for(int i=0; i<tlen; i++){ char si = s[i]; char ti = t[i]; if (si == ti || si == '?' || ti == '?'){ prefixlen++; } else { break; } } int suffixlen = 0; for(int i=0; i<tlen; i++){ char si = s[slen-i-1]; char ti = t[tlen-i-1]; if (si == ti || si == '?' || ti == '?') { suffixlen++; } else { break; } } for(int x=0; x<=tlen; x++){ if(x<=prefixlen && tlen-x<=suffixlen){ cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。