Cod sursa(job #2210932)

Utilizator AlexDabuDabu Alexandru AlexDabu Data 8 iunie 2018 17:39:40
Problema Potrivirea sirurilor Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 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++)
	{
		if (!B.compare(i, A.size(), A) )
		{
			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;
}