Pagini recente » Cod sursa (job #2230648) | Cod sursa (job #2841772) | Cod sursa (job #933246) | Cod sursa (job #129690) | Cod sursa (job #1232192)
#include <fstream>
#define MAX_MATCHES 1000
using namespace std;
int POSITIONS[MAX_MATCHES];
bool matches(string A, string B, int a_length int start)
{
for (int i = 0; i < a_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 a_length = A.length();
int b_length = B.length();
int n_matches = 0;
int i = 0;
while (i <= b_length)
{
if (matches(A, B, a_length, 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;
}