[ACM] POJ 1936 All in All (查找,一个串是否在另一个串中)

All in All

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 27521   Accepted: 11266

Description

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings
are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.

Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

Source

Ulm Local 2002

代码:

一开始想多了,想着要查找的串的第一个字母对应另一个串中的很多位置怎么办。。。其实不用只要匹配了一个字母待匹配的串就少了一个字母,不需要回溯。。所以直接设置两个指针直接模拟就可以了。。

代码:

#include <iostream>
#include <string.h>
using namespace std;
string s1,s2;
int len1,len2;

int main()
{
    while(cin>>s1>>s2)
    {
        int len1=s1.length();
        int len2=s2.length();
        int i=0,j=0;
        while(j<len2)
        {
            if(s1[i]==s2[j])
            {
                i++;
                j++;
                if(i==len1)
                {
                    cout<<"Yes"<<endl;
                    break;
                }
            }
            else
            {
                 j++;
                 if(j==len2)
                 {
                     cout<<"No"<<endl;
                     break;
                 }
            }
        }
    }
    return 0;
}

[ACM] POJ 1936 All in All (查找,一个串是否在另一个串中),布布扣,bubuko.com

时间: 2024-12-22 08:15:45

[ACM] POJ 1936 All in All (查找,一个串是否在另一个串中)的相关文章

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

[ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

[ACM] POJ 2796 Feel Good (求序列中子序列的和与子序列中的最小数最大乘积)

Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9186   Accepted: 2509 Case Time Limit: 1000MS   Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated

[ACM] poj 2456 Aggressive cows (二分查找)

Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5436   Accepted: 2720 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...

POJ 1936 All in All 题解

寻找一个串是否是另外一个字符串的子串序列. 可以想象主串是一连发子弹,而需要查找的子串是一队敌人,然后主串的字符是目标,把主串的所有子弹打完,是否能把子串的所有敌人消灭掉. 很简单的题目. #include <stdio.h> const int MAX_N = 100001; char seq[MAX_N], subSeq[MAX_N]; int main() { while (~scanf("%s %s", subSeq, seq)) { char *s = seq,

[ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)

Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14158   Accepted: 5697 Description Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and r

[ACM] POJ 2947 Widget Factory (高斯消元)

Widget Factory Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 4436   Accepted: 1502 Description The widget factory produces several different kinds of widgets. Each widget is carefully built by a skilled widgeteer. The time required to

[ACM] POJ 1442 Black Box (堆,优先队列)

Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7099   Accepted: 2888 Description Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empt

[ACM] POJ 1068 Parencodings(模拟)

Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19352   Accepted: 11675 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn