Cod sursa(job #2210929)

Utilizator AlexDabuDabu Alexandru AlexDabu Data 8 iunie 2018 17:29:52
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

ifstream fin("strmatch.in");
ofstream fout("strmatch.out");

string A, B;
int numberOfMatches = 0;
vector <int> indexListOfMatches;

void Read(void)
{
	fin >> A >> B;
}

void Match(void)
{
	int index = 0;
	bool match = true;
	for (unsigned int i = 0; i < B.size(); i++)
	{
		index = 0;
		match = true;
		while (match)
		{
			if (A.at(index) == B.at(i + index))
			{
				index++;
			}
			else
			{
				match = false;
			}
			if (index == A.size() || i + index == B.size())
			{
				break;
			}
		}
		if (index == A.size() && match)
		{
			numberOfMatches++;
			indexListOfMatches.push_back(i);
		}
	}
}

void Print(void)
{
	fout << numberOfMatches << '\n';
	int limitIndex;
	if (numberOfMatches > 1000)
	{
		limitIndex = 1000;
	}
	else
	{
		limitIndex = numberOfMatches;
	}
	for (int i = 0; i < limitIndex; i++)
	{
		fout << indexListOfMatches.at(i) << ' ';
	}
}

int main(void)
{
	Read();
	Match();
	Print();
	return 0;
}