Merge 12e9d081b9 into 32c77f5123
commit
7930829280
@ -1,87 +1,56 @@
|
|||||||
/*#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
char s[100000], p[100000];
|
|
||||||
int next[100000];
|
|
||||||
void getNext(char* P)
|
|
||||||
{
|
|
||||||
int lenP = strlen(P);
|
|
||||||
next[0] = -1;
|
|
||||||
int k = -1, i = 0;
|
|
||||||
while (i < lenP - 1)
|
|
||||||
if (k == -1 || P[k] == P[i])
|
|
||||||
i++, k++, next[i] = (p[i] == p[k]) ? next[k] : k;
|
|
||||||
else k = next[k];
|
|
||||||
}
|
|
||||||
int match(char* S, char* P)
|
|
||||||
{
|
|
||||||
int lenS = strlen(S), lenP = strlen(P), i = 0, j = 0;
|
|
||||||
while (i < lenS && j < lenP)
|
|
||||||
if (j == -1 || S[i] == P[j])
|
|
||||||
i++, j++;
|
|
||||||
else
|
|
||||||
j = next[j];
|
|
||||||
return j == lenP ? i - j : -1;
|
|
||||||
}
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
scanf("%d", &n);
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
scanf("%s%s", p, s);
|
|
||||||
getNext(p);
|
|
||||||
char* str = s;
|
|
||||||
int pos = match(str, p), ans = 0;
|
|
||||||
while (pos != -1)
|
|
||||||
{
|
|
||||||
ans++;
|
|
||||||
str += pos + 1;
|
|
||||||
pos = match(str, p);
|
|
||||||
}
|
|
||||||
printf("%d\n", ans);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
#include<cstdio>
|
#include<cstdio>
|
||||||
#include<cstring>
|
#include<cstring>
|
||||||
using namespace std;
|
|
||||||
const int mt = 1e6 + 5;
|
const int mt = 1e6 + 5;
|
||||||
char x[mt], y[mt], next[mt];
|
|
||||||
|
char x[mt], y[mt];
|
||||||
int m, n;
|
int m, n;
|
||||||
void pre()
|
|
||||||
{
|
template<typename T>
|
||||||
int i = 0, j = next[0] = -1;
|
int cnt(T *x, int m, T *y, int n)
|
||||||
while (i != m)
|
|
||||||
{
|
|
||||||
if (-1 == j || y[i] == y[j]) next[++i] = ++j;
|
|
||||||
else j = next[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int cnt()
|
|
||||||
{
|
{
|
||||||
pre();
|
if (m > n) return 0;
|
||||||
int i = 0, j = 0, ans = 0;
|
if (m == 1)
|
||||||
while (i != n && j != m)
|
{
|
||||||
{
|
int ret = 0;
|
||||||
if (-1 == j || y[i] == x[j]) i++, j++;
|
for (int i = 0; i < n; ++i)
|
||||||
else j = next[j];
|
{
|
||||||
if (j == m)
|
if (y[i] == x[0]) ++ret;
|
||||||
ans++, i -= j - 1, j = -1;
|
}
|
||||||
}
|
return ret;
|
||||||
return ans;
|
}
|
||||||
|
T *next = new T[n]();
|
||||||
|
int i = 0;
|
||||||
|
int j = next[0] = -1;
|
||||||
|
while (i < m)
|
||||||
|
{
|
||||||
|
if (-1 == j or y[i] == y[j]) next[++i] = ++j;
|
||||||
|
else j = next[j];
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
int ans = 0;
|
||||||
|
while (i < n and j < m)
|
||||||
|
{
|
||||||
|
if (-1 == j or y[i] == x[j]) ++i, ++j;
|
||||||
|
else j = next[j];
|
||||||
|
if (j == m)
|
||||||
|
++ans, i -= j - 1, j = -1;
|
||||||
|
}
|
||||||
|
delete next;
|
||||||
|
return ans;
|
||||||
}
|
}
|
||||||
int main()
|
|
||||||
|
|
||||||
|
int main(const int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
scanf("%d", &t);
|
scanf("%d", &t);
|
||||||
while (t--)
|
while (t --> 0)
|
||||||
{
|
{
|
||||||
scanf("%s", x);
|
scanf("%s", y);
|
||||||
scanf("%s", y);
|
scanf("%s", x);
|
||||||
m = strlen(x), n = strlen(y);
|
printf("%d\n", cnt(x, strlen(x), y, strlen(y)));
|
||||||
//cout<<m<<endl<<n<<endl;
|
}
|
||||||
//cout<<x<<endl<<y<<endl;
|
return 0;
|
||||||
printf("%d\n", cnt());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in new issue