Pagini recente » Cod sursa (job #1967743) | Cod sursa (job #2786968) | Cod sursa (job #570843) | Cod sursa (job #137030) | Cod sursa (job #1922431)
#include <fstream>
#include <string>
#define maxSize 2000001
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
string s1, s2;
bool v[1001];
int main()
{
fin>>s1>>s2;
int nr = 0;
int i = -1;
while(1) {
i = s2.find(s1, i + 1);
if (i == -1) {
break;
}
nr++;
if (nr <= 1000) {
v[i] = true;
}
}
fout<<nr<<'\n';
for (int i = 0; i <= 1000; i++) {
if(v[i] == true) {
fout<<i<<' ';
}
}
fin.close();
fout.close();
return 0;
}
/*
#include <fstream>
#include <cstring>
#include <queue>
#define maxSize 2000001
#define prim 73
#define mod 104729
#define mod2 104743
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char s1[maxSize], s2[maxSize];
queue <int> q;
int main()
{
fin.getline(s1, maxSize);
fin.getline(s2, maxSize);
int l1 = strlen(s1) - 1;
int l2 = strlen(s2) - 1;
long long hash11 = 0, hash12 = 0, hash21= 0, hash22 = 0, power = 1;
if (l2 < l1) {
fout<<"0";
return 0 ;
}
hash11 = s1[0];
hash12 = s1[0];
hash21 = s2[0];
hash22 = s2[0];
for(int i = 1; i <= l1; i++) {
power = (power * prim) % mod;
hash11 = (hash11 + s1[i] * power)% mod;
hash21 = (hash21 + s2[i] * power)% mod;
hash12 = (hash12 + s1[i] * power)% mod2;
hash22 = (hash22 + s2[i] * power)% mod2;
}
if(l2 == l1 && hash11 == hash21 && hash12 == hash22) {
fout<<"1\n0";
return 0;
}
int nr = 0;
for (int i = l1 + 1; i <= l2; i++) {
if(hash11 == hash21 && hash12 == hash22) {
nr++;
q.push(i - l1 -1);
}
hash21 = (((hash21 - s2[i - l1 - 1]) / prim) + (s2[i] * power) % mod) % mod;
hash22 = (((hash22 - s2[i - l1 - 1]) / prim) + (s2[i] * power) % mod2) % mod2;
}
if(hash11 == hash21 && hash12 == hash22) {
nr++;
q.push(l2 - l1);
}
fout<<nr<<'\n';
int k = 0;
while(!q.empty()) {
fout<<q.front()<<' ';
k++;
if(k == 1000)
break;
q.pop();
}
fin.close();
fout.close();
return 0;
}*/