Cod sursa(job #645279)

Utilizator the_snyper06FMI - ALexandru Mihai the_snyper06 Data 8 decembrie 2011 22:32:51
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#define Check() if (++i == 800001) {fread (buff, 1, 800001, stdin); i = 0;}

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

inline void Read(char *s) {
	int k = -1;
	s[k + 1] = '\0';
	while ((buff[i] < '0' || buff[i] > '9') && (buff[i] < 'a' || buff[i] > 'z') && (buff[i] < 'A' || buff[i] > 'Z')) Check();
	while ((buff[i] >= '0' && buff[i] <= '9') || (buff[i] >= 'a' && buff[i] <= 'z') || (buff[i] >= 'A' && buff[i] <= 'Z')) {
		s[++k] = buff[i];
		Check();
	}
	s[++k] = '\0';
}

int main() {
	
	freopen("strmatch.in", "r", stdin), freopen("strmatch.out", "w", stdout);
	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;
}