Cod sursa(job #1232188)

Utilizator daniel.amarieiDaniel Amariei daniel.amariei Data 22 septembrie 2014 12:40:38
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#define MAX_MATCHES 1000
using namespace std;

int POSITIONS[MAX_MATCHES];

bool matches(string A, string B, int start)
{
	int length = A.length();
	for (int i = 0; i < length; ++i)
	{
		if (A[i] != B[start + i])
		{
			return false;
		}
	}
	
	return true;
}

int main()
{
	ifstream ifs("strmatch.in");
	ofstream ofs("strmatch.out");
	
	string A, B; 
	ifs >> A >> B;
	
	int b_length = B.length();
	
	int n_matches = 0;
	int i = 0;
	while (i <= b_length)
	{
		if (matches(A, B, i)) 
		{
			if (n_matches < MAX_MATCHES)
				POSITIONS[n_matches++] = i;
		} 

		++i;
	}
	
	ofs << n_matches << "\n";
	for (int i = 0; i < n_matches; ++i)
		ofs << POSITIONS[i] << " ";

	return 0;
}