Cod sursa(job #472499)

Utilizator ilie.danilaIlie Teodor Danila ilie.danila Data 25 iulie 2010 13:57:04
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <string>
#include <vector>

using namespace std;

char a[2000000];
char b[2000000];

vector<int> solutions;

int main()
{
	ifstream f("strmatch.in");
	ofstream g("strmatch.out");

	f >> a >> b;

	f.close();

	string A(a);
	string B(b);
	
	bool isOK;
	int position = 0;
	do
	{
		isOK = false;
		position = B.find(A, position);
		if( position != string::npos )
		{
			solutions.push_back(position);
			position++;
			isOK = true;
		}
		
	}while(isOK);

	g << solutions.size() << "\n";

	for (int i = 0; i < solutions.size(); i++)
		g << solutions[i] << " ";
	g << "\n";

	return 0;
}