Cod sursa(job #244225)

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

int main() {
	char *str, *substr, *buffer = new char[2000001];
	FILE* io;
	io = fopen("strmatch.txt", "r");
	fgets(buffer, 2000000, io);
	substr = new char[strlen(buffer)+1];
	strcpy(substr, buffer);
	fgets(buffer, 2000000, io);
	str = new char[strlen(buffer)+1];
	strcpy(str, buffer);
	delete[] buffer;
	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("strmatch2.txt", "w");
	fprintf(io, "%d\n", y);
	for(int i = 0; i < y && i < 1000; i++)
		fprintf(io, "%d ", results[i]);
}