Gym 100959L_String Modification(模擬)

傳送門

題意:給一個字符串s,每次可以在一個字符的右邊加一個與這個字符不同的字符,問是否能變成字符串t。

思路:第一個不相等 || 第一個連續的的個數s

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
char s1[N],s2[N];
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    scanf("%s%s",s1+1,s2+1);
    int len1=strlen(s1+1);
    int len2=strlen(s2+1);
    int i=1,j=1;
    while(s1[i]==s1[i+1])++i;
    while(s2[j]==s2[j+1])++j;
    if(i<j || s1[1]!=s2[1] || len1>len2){
        puts("No");
        return 0;
    }
    j=1;
    int flag=0;
    for(int i=1;i<=len1;i++){
        while(j<=len2 && s1[i]!=s2[j]) ++j;
        if(s1[i]!=s2[j]) flag=1;
        else ++j;
    }

    printf("%s\n",flag?"No":"Yes");
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章