CF 1553 D. Backspace(双指针 贪心)

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    
    
    string t,s;
    cin>>t>>s;
    int q=t.size()-1,p=s.size()-1;
    while(q>=0 && p>=0)
    {
    
    
        if(t[q]==s[p]){
    
    q--;p--;}//t[p]==s[p]
        else q-=2;//p 不用回退
    }
    if(p>=0)puts("NO");
    else puts("YES");
}
int main()
{
    
    
    int T;
    scanf("%d",&T);
    while(T--)solve();
    return 0;
}

Supongo que te gusta

Origin blog.csdn.net/Ambrumf/article/details/120846841
Recomendado
Clasificación