[ACM] poj 1936 all in all (find whether one string is in another)

Source: Internet
Author: User

All in all
Time limit:1000 ms   Memory limit:30000 K
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 subsequenceperson compressionverdi vivavittorioemanuelerediitaliacasedoesmatter casedoesmatter

Sample output

 
Yesnoyesno

Source

Ulm Local 2002 Code:

I thought too much at first, and thought about how the first letter of the string to be searched corresponds to many locations in the other string... In fact, you don't need to drop a letter for a string that matches a letter, and do not need to trace back .. Therefore, you can directly set two pointers for direct simulation ..

Code:

 
# 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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.