Pagini recente » Cod sursa (job #1215238) | Cod sursa (job #1317168) | Cod sursa (job #2362058) | Cod sursa (job #1221098) | Cod sursa (job #2855249)
#include <fstream>
#include <deque>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cstring>
#include <climits>
#define MOD 104659
using namespace std ;
ifstream cin ("strmatch.in") ;
ofstream cout ("strmatch.out") ;
string a, b, rest ;
void aflarest()
{
string auxa = a ;
for(int f = 1 ; f < a.size() ; f ++)
{
string st = a.substr(0, f) ;
string dr = a.substr(a.size() - f, a.size() - 1) ;
if(st == dr)rest = a.substr(f, a.size() - 1) ;
}
}
vector<int> rez ;
bool incaunul(char *ptr)
{
for(int f = 0 ; f < rest.size() ; f ++)
if(ptr[f] != rest[f])return 0 ;
rez.push_back((ptr - &b[0]) - (a.size() - rest.size())) ;
return 1 ;
}
int main()
{
cin >> a >> b ;
aflarest() ;
char *ptr = &b[0] ;
while(ptr = strstr(ptr, &a[0]))
{
rez.push_back((ptr - &b[0])) ;
ptr += a.size() ;
while(incaunul(ptr))
ptr += rest.size() ; /// ???
}
cout << rez.size() << endl ;
int n = min((int)rez.size(), 1000) ;
for(int f = 0 ; f < n ; f ++)
cout << rez[f] << " " ;
return 0 ;
}