Ultraviolet A 10340-all in all

Source: Internet
Author: User

Link:

Http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & category = 113 & page = show_problem & problem = 1281

Original question:

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 stringsSAndT, You have to decide whetherSIs a subsequenceT, I. e. If you can remove characters fromTSuch that the concatenation of the remaining characters isS.

Input Specification

The input contains several testcases. Each is specified by two stringsS, TOf alphanumeric ASCII characters separated by whitespace. input is terminated by EOF.

Output Specification

For each test case output, ifSIs a subsequenceT.

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample output

Yes
No
Yes
No

Analysis and Summary:To determine whether a string is a substring of another string.
Code:
/* *  UVa: 10340 - All in All *  Time: 0.008s *  Author: D_Double */#include<iostream>#include<cstdio>#include<cstring>using namespace std;char str1[1000000], str2[1000000];bool judge(){    int pos=0, i;    for(i=0; i<strlen(str1); ++i){        bool flag=false;        while(pos < strlen(str2)){            if(str2[pos]==str1[i])                break;            ++pos;        }        if(pos==strlen(str2)) return false;        ++pos;    }    if(i==strlen(str1)) return true;    return false;}int main(){    while(scanf("%s %s",str1,str2)!=EOF){        if(judge()) printf("Yes\n");        else printf("No\n");    }    return 0;}

-- The meaning of life is to give it meaning.

Original Http://blog.csdn.net/shuangde800 , By d_double (reprinted, please mark)

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.