Cod sursa(job #681825)

Utilizator DSzprogDombi Szabolcs DSzprog Data 17 februarie 2012 20:56:14
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <cstdio>

int n;
int m;
char a[2000002];
char b[2000002];

FILE * f1 = fopen("strmatch.in", "rt");
FILE * f2 = fopen("strmatch.out", "wt");

int main() {
	fscanf(f1, "%s", a);
	fscanf(f1, "%s", b);
	while(a[++n]);
	while(b[++m]);
	a[n] = '_';

	fprintf(f2, "        \n");
	int count = 0;
	int q = n + 1;
	int p = m - n + 1;
	for (int i = 0; i < p; ++i) {
		int j = 0;
		int k = i;
		while (a[j++] == b[k++]);
		if (j == q) {
			if (++count <= 1000) {
				fprintf(f2, "%d ", i);
			}
		}
	}
	fseek(f2, 0, SEEK_SET);
	fprintf(f2, "%d", count);
	fclose(f1);
	fclose(f2);
}