UVa10340 All in All (子序列)

输入两个字符串s和t,判断是否可以从t中删除0个或者多个字符(其他字符顺序不变),得到字符串s。例如,abcde可以得到bce,但无法得到cb。

Input

输入多组数据

每组一行包含两个字符串s和t,两字符串之间用空格隔开。

字符串长度在100000以内

Output

输出Yes或No

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

解答:#include<iostream>#include<cstring>#include<cstdio>using namespace std;string s,t;int ls,lt;int main(){    while(cin>>t>>s)    {        ls=s.length()-1;        lt=t.length()-1;        while(ls>=0&&lt>=0)        {            if(t[lt]!=s[ls]) ls--;            else            {                lt--;                ls--;            }        }        if(lt==-1) printf("Yes\n");        else printf("No\n");    }}

原文地址:https://www.cnblogs.com/satans/p/11111388.html

时间: 2024-07-30 16:16:19

UVa10340 All in All (子序列)的相关文章

UVA10340 All in All子序列

Problem E All in All Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a cleve

14-高效求最长公共子序列(二维数组存不下)

/*                                   See LCS again时间限制:1000 ms  |  内存限制:65535 KB难度:3 描述 There are A, B two sequences, the number of elements in the sequence is n.m; Each element in the sequence are different and less than 100000. Calculate the length

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

最大连续子序列和

对于给定的数组 numnum,一个长度为 ss 的连续子序列是指由 num_i,num_{i+1},num_{i+2}\ldots,num_{i+s-1}num?i??,num?i+1??,num?i+2??…,num?i+s−1?? 组成的序列.数组中的元素有可能为正数.负数或 00.你需要从数组中找出元素总和最大的一个连续子序列. 比如,对于数组 1,-3,2,6,-5,81,−3,2,6,−5,8,其最大连续子序列之和是 2+6-5+8=112+6−5+8=11. 对于一段区间内的最大连续

最长公共子序列的代码实现

关于最长公共子序列(LCS)的相关知识,http://blog.csdn.net/liufeng_king/article/details/8500084 这篇文章讲的比较好,在此暂时不再详说. 以下是我代码实现两种方式:递归+递推: 1 #include <bits/stdc++.h> 2 using namespace std; 3 int A[100]; 4 int B[100]; 5 6 //int B[]={2,3,5,6,9,8,4}; 7 int d[100][100]={0};

hdu1231 最大连续子序列

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22849    Accepted Submission(s): 10135 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j

计算数组的最大子序列之和

问题描述: 计算一个给定数组的最大子序列之和 分析: 有三种方法: 1,扫描3遍,可以计算所有的子序列之和,但是复杂度为N^3. 2,扫描2遍,计算以任意元素开始的和,如果大于当前的最大值则将最大值付给它,复杂度为N^2. 3,扫描一遍,计算任意元素开始的值,如果小于零则清零,否则继续往后加. 代码实现: package c02; /**  * @project: DataStructureAndAlgorithmAnalysis  * @filename: MaxSubSum  * @vers

HDU 3998 Sequence (最长递增子序列+最大流SAP,拆点法)经典

Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1666    Accepted Submission(s): 614 Problem Description There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequ

LintCode-乘积最大子序列

找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 分析:访问到每个点的时候,以该点为子序列的末尾的乘积,要么是该点本身,要么是该点乘以以前一点为末尾的序列,注意乘积负负得正,故需要记录前面的最大最小值. 代码: class Solution { public: /** * @param nums: a vector of integers * @return: an integer */ int m