zoukankan      html  css  js  c++  java
  • 构造 HDOJ 5414 CRB and String

    题目传送门

    题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串

    构造:首先lens > lent 或者 s[1] != t[1] 一定是No,然后t最前面相同字符长度的部分在s中要相同,否则不能插入,之后的部分只要相同的部分全部存在,不同的部分可以随便插

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015-8-20 15:29:43
    * File Name     :I.cpp
    ************************************************/

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;

    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int MAXN = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    char s[MAXN], t[MAXN];

    bool judge(void)    {
       int lens = strlen (s + 1);
       int lent = strlen (t + 1);
       if (lens > lent || s[1] != t[1])    return false;
       int i, j;
       for (j=2; j<=lent; ++j) {
           if (t[j] != t[1])   break;
       }
       for (i=1; i<j; ++i) {
           if (s[i] != t[i])   return false;
       }
       while (i <= lens)    {
           while (j <= lent && s[i] != t[j])   ++j;
           if (j > lent)   return false;
           i++;    j++;
       }
       return true;
    }

    int main(void)    {     //HDOJ 5414 CRB and String
       int T;  scanf ("%d", &T);
       while (T--) {
           scanf ("%s%s", s + 1, t + 1);
           puts (judge () ? "Yes" : "No");
       }

       return 0;
    }
    编译人生,运行世界!
  • 相关阅读:
    11.4 final类
    11.3 final方法
    【GIS】GIS坐标系
    【其他】短信轰炸
    【js】js传递对象
    【注解】Autowired
    【js】vue.js v-model
    【问题】ajax两种传递id值方式的区别
    【随笔】6.高筑墙 广积粮 缓称王
    【随笔】5.多恩亲王 Red Viper 奥伯伦之死。
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4746320.html
Copyright © 2011-2022 走看看