Cod sursa(job #796855)

Utilizator noctavianNastasie Ion Octavian noctavian Data 12 octombrie 2012 19:23:34
Problema Potrivirea sirurilor Scor 38
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main() {
	string A, B;
	ifstream in("strmatch.in");
	in >> A >> B;
	in.close();

	vector<int> poz;
	int nr_matches = 0;
	int N = B.length();
	int M = A.length();

	for(int i = 0; i < N-M; i++) {
		if(B.compare(i,M, A) == 0) {
			nr_matches++;
			if(nr_matches <= 1000)
				poz.push_back(i);
		}
	}

	ofstream out("strmatch.out");
	out << nr_matches << endl;
	for(int i = 0; i < poz.size(); i++) 
		out << poz[i] << " ";
	out.close();

    return 0;
}