Codeforces 625B string Simulation + thinking

Source: Internet
Author: User

Test instructions gives the string A and B can change a single character in A to # ask at least how many times a will not find B in a

The first thing is to use strstr because if you find can change Strstr (A, B)-a+1 to # that is, change the first letter with the while loop strstr to do the problem

However, change the first letter is not possible because there may be overlapping, such as in the LLL to find ll change the first one can find out but in fact, only one can be changed

And then I thought I could change the last one, but with Strstr.

So finally came up with a violent sweep of the magic solution. Because a maximum of a is five square B is 30 the maximum is 3 times 10 of the six parties. The result 46ms is good ...

Just glanced at someone else's 15ms code. The length of the solution using STRSTR should not exceed 300bytes ... Sure enough, you should try ...

#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h >using namespace Std;int Main () {char S[100050];char q[250];while (~scanf ("%s", s)) {    scanf ("%s", q);    int ans=0;    int L1=strlen (s);    int L2=strlen (q);    for (int i=0;i<l1;i++)    {        int ok=true;        if (I+L2>L1) break            ;        for (int k=0;k<l2;k++)        {            if (S[i+k]==q[k])            continue;            else            {                ok=false;                break;            }        }        if (ok==true)        {            ans++;            s[i+l2-1]= ' # ';        }    }    printf ("%d\n", ans);}}

And then someone else's.

Codeforces 625B string Simulation + thinking

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.