• 构造 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;
    }
    编译人生,运行世界!
  • 相关阅读:
    使用 Scrapy 爬取股票代码
    基于python开发的股市行情看板
    基于django的视频点播网站开发
    一个基于php+mysql的外卖订餐网站(带源码)
    线性表概述及单链表的Java实现
    使用github pages搭建个人博客
    解决SpannableString在Android组件间传递时显示失效的问题
    Android进程间通信(一):AIDL使用详解
    Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)
    Linux创建普通用户
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4746320.html
Copyright © 2020-2023  润新知