Pagini recente » Cod sursa (job #832110) | Cod sursa (job #50481) | Cod sursa (job #2415830) | Cod sursa (job #2804990) | Cod sursa (job #2210929)
#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;
}