UVa 10340 all on all (water problem, matching)

Source: Internet
Author: User
Tags first string

Test instructions: Given two strings, ask if the first string can be obtained from the second string by removing 0 or more characters.

Analysis: That is a character of a character match, if the match on the back walk, the final judgment is not equal to the length can be.

The code is as follows:

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include < Cmath>using namespace std;string S1, S2;int main () {while    (cin >> S1 >> S2) {        if (s1.size () > S2.s Ize ()) {  cout << "no\n";  Continue;  }        int j = 0;        for (int i = 0; i < s2.size (), ++i)            if (j = = S1.size ()) break  ;            else if (s2[i] = = S1[j])  ++j;        if (j = = S1.size ())  cout << "yes\n";        else  cout << "no\n";    }}

UVa 10340 all on all (water problem, matching)

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.