Cod sursa(job #647294)

Utilizator the_snyper06FMI - ALexandru Mihai the_snyper06 Data 11 decembrie 2011 13:17:34
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include<cstdio>
#include<string>
#include<vector>
#define Check() if (++i == 4096) {fread (buff, 1, 4096, stdin); i = 0;}

using namespace std;
string str1, str2;
vector <int> L;
size_t found;
char s1[2000001], s2[2000001], buff[4096];
int i;

inline void Read(char *s) {
	int k = -1;
	s[k + 1] = '\0';
	while (buff[i] == '\n') Check();
	while (buff[i] != '\n') {
		s[++k] = buff[i];
		Check();
	}
	s[++k] = '\0';
}

int main() {
	
	freopen("strmatch.in", "r", stdin), freopen("strmatch.out", "w", stdout);
	fread (buff, 1, 4096, stdin);
	Read(s1); str1 = s1; //printf("%s\n", s1);
	Read(s2); str2 = s2; //printf("%s\n", s2);
	
	found = str2.find(str1);
	while(found != string::npos) {
		L.push_back(int(found));
		found = str2.find(str1, found + 1);
	}
	
	printf("%d\n", L.size());
	for(int i = 0; i < int(L.size()) && i < 1000; i++)
		printf("%d ", L[i]);
	printf("\n");
	
	return 0;
}