Stay Hungry,Stay Foolish!

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;
}
 

 

posted @ 2023-02-04 11:56  lightsong  阅读(14)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel