Backwards processing thinking-including string matching and nine-degree 1510 substitution for empty Gegian-offer03

Source: Internet
Author: User

Backwards is a good technique for dealing with strings and so on. For example, it has nothing to do with this problem, but the difficulty and meaning are better.

For example, a non-exact match is one character mismatch.

Well, there's actually a good way to do it:

Pattern string: AACB

A string to match:

1, Aamb

2. ACB

3, Aamdb

This time can actually match first, calculate the number of matching characters P1, then reverse matching, calculate the number of matches P2, and then see the relationship between P1+P2 and the length of the pattern string

Well, above ... Haven't done any specific questions yet.

Look at this problem again, but also the idea of handling strings backwards: O (n) Disposed of

#include <cstdio> #include <cstring> #include <iostream> #include <cstdio> #include < algorithm>using namespace Std;const int SIZE = 1000000+1;char Str[size];char ans[size*2];int leng;void Solve () {    Leng = strlen (str);    int blank = 0;    for (int i=0;i<leng;i++) {        if (str[i] = = ") blank++;    }    int ansleng = Blank*2+leng;    int oldptr = leng-1;    int newptr = ansleng-1;    Ans[ansleng] = ' + ';    while (oldptr>=0) {        if (str[oldptr] = = ") {            ans[newptr]= ' 0 ';            ans[--newptr]= ' 2 ';            ans[--newptr]= '% ';        } else{            ans[newptr]=str[oldptr];        }        cout << newptr << "  << oldptr << Endl;        --newptr;        --oldptr;    }    printf ("%s\n", ans);} int main () {    //freopen ("03.txt", "R", stdin);    while (Cin.getline (str,size)) {        //cout << str << endl;        Solve ();    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Backwards processing thinking-including string matching and nine-degree 1510 substitution for empty Gegian-offer03

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.