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