Pagini recente » Cod sursa (job #1130328) | Cod sursa (job #1139248) | Cod sursa (job #346442) | Cod sursa (job #2710482) | Cod sursa (job #1630230)
#include <iostream>
#include <fstream>
#include <string.h>
#include <vector>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
char a[2000005], b[2000005];
int v[2000005];
vector<int> x;
int main()
{
f >> a >> b;
int n = strlen( a );
int m = strlen( b );
int i, j;
i = 0;
v[ i ] = 0;
for( j = 1; j < n; j ++ )
{
while( i > 0 && a[i] != a[j] )
i = v[i - 1];
if( a[i] == a[j] )
i ++;
v[j] = i;
}
i = 0;
for( j = 0; j < m; j ++ )
{
while( i > 0 && a[i] != b[j] )
i = v[ i - 1 ];
if( a[i] == b[j] )
i ++ ;
if( i == n )
{
x.push_back(j-i+1);
i = v[i - 1];
}
}
int ans;
if( x.size() > 1000 )
ans = 1000;
else
ans = x.size();
g<<ans<<'\n';
for( int i = 0; i < ans; i ++ )
g<<x[i]<<" ";
return 0;
}