Cod sursa(job #1457108)

Utilizator tony.hegyesAntonius Cezar Hegyes tony.hegyes Data 2 iulie 2015 18:16:27
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;

int main(int argc, char **argv)
{
	// INPUT
	ifstream indata("strmatch.in");
	char A[200001], B[200001];
	
	indata >> B >> A;
	indata.close();
	
	// PATTERN MATCHING
	vector<int> positions;
	int n = strlen(A), m = strlen(B);
	
	for (int i = 0; i + m <= n; i++) {
		int q = 0;
		while(q < m && A[i + q] == B[q]) {
			q++;
		}
		if (q == m) {
			positions.push_back(i);
		}
	}
	
	// OUTPUT
	ofstream outdata("strmatch.out");
	outdata << positions.size() << "\n";
	for (size_t i = 0; i < positions.size(); i++) {
		outdata << positions[i] << " ";
	}
	outdata.close();
	return 0;
}