Pagini recente » Cod sursa (job #2255758) | Cod sursa (job #56525) | Cod sursa (job #2540125) | Cod sursa (job #371094) | Cod sursa (job #2709280)
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <climits>
#include <queue>
#define MOD 666013
using namespace std;
ifstream cin("strmatch.in") ;
ofstream cout("strmatch.out") ;
vector<int> v ;
int process(string a)
{
int k = 0 ;
for(int f = a.size() - 1 ; f >= 0 ; f --)
{
/// dau match la primele f caract si ultimele f caract
string st = a.substr(0, f) ;
string dr = a.substr(a.size() - f, a.size()) ;
if(st == dr)return a.size() - f ;
}
return a.size() ;
}
int main()
{
string a, b ;
cin >> a >> b ;
int k = process(a) ;
string remainder = a.substr(a.size() - k, a.size() - k + a.size() - k) ; /// pe asta il cautam de la capat, daca este prezent acolo atunci continuam altfel doar cautam de la capat tot striungul
char *ptr = &b[0], *auxptr ;
while(auxptr = strstr(ptr, &a[0]))
{
v.push_back(auxptr - &b[0]) ;
/// lam gasit pe a in auxptr
/// acuma trebe sa vedem daca la sfarsitul lui a se afla remainder
int poz = auxptr - &b[0] + a.size() ;
while(remainder.size() && b.substr(poz, remainder.size()) == remainder)
{
poz += remainder.size() ; /// poz devine sfarsitul lui remainder
v.push_back(poz - a.size()) ;
}
ptr = &b[poz] ;
///ptr = auxptr + k ;
}
cout << v.size() << endl ;
for(int f = 0 ; f < v.size() && f < 1000 ; f ++)
cout << v[f] << " " ;
return 0 ;
}