Cod sursa(job #923317)

Utilizator MciprianMMciprianM MciprianM Data 23 martie 2013 13:29:30
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>

using namespace std;

static const int MAXN = 2000001, MAXA = 1000;
char T[MAXN], P[MAXN];
int A[MAXA];

int main() {
	int ans = 0;
	ifstream f("strmatch.in");
	f >> P >> T;
	f.close();
	for(int i = 0; T[i]; i++) {
		bool match = true;
		for(int j = 0; P[j]; j++) {
			if(P[j] != T[i + j]) {
				match = false;
				break;
			}
		}
		if(match) {
			if(ans < MAXA)	A[ans] = i;
			ans++;
		}
	}
	ofstream g("strmatch.out");
	g << ans << endl;
	for(int i = 0; i < MAXA && i < ans; i++) {
		g << A[i] << ' ';
	}
	g << endl;
	g.close();
	return 0;
}