Pagini recente » Cod sursa (job #1461472) | Istoria paginii utilizator/oana-maria | Cod sursa (job #2750818) | Cod sursa (job #1889240) | Cod sursa (job #1593638)
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
char s1[2000003];
char s2[2000003];
int val[1003];
char *p1 = s1;
char *p2 = s2;
int cnt;
int main() {
in.getline(s1, 2000003);
in.getline(s2, 2000003);
string A(p1);
string B(p2);
//cout << A << endl;
int len1 = strlen(s1);
int len2 = strlen(s2);
int c = B.find(A, 0);
while(c != string::npos) {
if(cnt < 1001)
val[cnt++] = c;
else
cnt++;
c = B.find(A, c+1);
}
//char *o = find(p2, p2+len, p1);
/*char *a = search(p2, p2+len2, p1, p1+len1);
int c;
while(c != len2) {
a = search(p2+c+1, p2+len2, p1, p1+len1);
c = a-p2;
val[cnt++] = c;
}*/
/*while(*p2 != '\n' && *p2 != '\0') {
if(*p2 == *p1) {
bool eq = true;
while(*p1 != '\n' && *p1 != '\0') {
if(*p1 != *p2) {
eq = false;
break;
}
p1++;
p2++;
}
p2 -= p1-s1;
if(eq)
val[cnt++] = p2 - s2;
p1 = s1;
}
p2++;
}*/
out << cnt << '\n';
for(int i = 0; i < cnt; i++) {
if(i == 1000)
break;
out << val[i] << " ";
}
return 0;
}