Pagini recente » Cod sursa (job #2078746) | Monitorul de evaluare | Cod sursa (job #2591640) | Cod sursa (job #2478082) | Cod sursa (job #1593570)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
char s1[2000003];
char s2[2000003];
int val[2000003];
char *p1 = s1;
char *p2 = s2;
int cnt;
int len;
int main() {
in.getline(s1, 2000003);
in.getline(s2, 2000003);
len = strlen(s1);
bool f = (len%2==1);
while(*p2 != '\n' && *p2 != '\0') {
if(*p2 == *p1) {
bool eq = true;
while(p1-s1 < len-f*2) {
//cout << "CMP1 " << *p1 << " " << *(p1+1) << endl;
if(*p1 != *p2 || *(p1+1) != *(p2+1)) {
eq = false;
break;
}
p1 += 2;
p2 += 2;
}
if(f) {
if(*p1 != *p2) {
eq = false;
// cout << "CMP2 " << *p1 << endl;
}
}
//cout << endl;
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;
}