Pagini recente » Cod sursa (job #3246415) | Cod sursa (job #1349852) | Cod sursa (job #3132336) | Cod sursa (job #2123293) | Cod sursa (job #1631539)
#include <iostream>
#include <fstream>
#include <string.h>
#include <vector>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
const int N = 20000005;
char a[20000005], b[20000005];
int v[20000005];
vector<int> x;
int main()
{
f.getline(a , N);
f.getline(b , N);
int n = strlen( a );
int m = strlen( b );
for( int i = n; i > 0; i -- )
a[i] = a[i-1];
for( int i = m; i > 0; i -- )
b[i] = b[i-1];
a[n+1] = b[m+1] = '\0';
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-n);
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;
}