Cod sursa(job #244231)

Utilizator LoLFactorPascu Vlad LoLFactor Data 14 ianuarie 2009 18:48:43
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
	char *str = new char[2000001], *substr = new char[2000001];
	FILE* io;
	io = fopen("strmatch.in", "r");
	fgets(substr, 2000000, io);
	fgets(str, 2000000, io);
	fclose(io);
	substr[strlen(substr)-1] = '\0';
	vector<int> results;
	char* x = str-1;
	do{
		x = strstr(x+1, substr);
		results.push_back(x-str);
    }while(x != NULL);
	int y = results.size()-1;
	io = fopen("strmatch.out", "w");
	fprintf(io, "%d\n", y);
	for(int i = 0; i < y && i < 1000; i++)
		fprintf(io, "%d ", results[i]);
}