Pagini recente » Cod sursa (job #96583) | Rating Birsan Eva (Birsan_Eva) | Cod sursa (job #1250745) | Cod sursa (job #2722115) | Cod sursa (job #1630997)
#include <iostream>
#include <fstream>
#include <string.h>
#include <vector>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
char a[20000005], b[20000005];
int v[2000005];
vector<int> x;
int main()
{
f >> (a + 1) >> (b + 1) ;
int n = strlen( a + 1 );
int m = strlen( b + 1 );
int i, j;
i = 0;
v[ 1 ] = 0;
for( j = 2; j <= n; j ++ )
{
while( i > 0 && a[i + 1] != a[j] )
i = v[i];
if( a[i + 1] == a[j] )
i ++;
v[j] = i ;
}
i = 0;
for( j = 1; j <= m; j ++ )
{
while( i > 0 && a[i+1] != b[j] )
i = v[ i ];
if( a[i + 1] == b[j] )
i ++ ;
if( i == n )
{
x.push_back(j-i);
i = v[i];
}
}
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;
}