Pagini recente » Istoria paginii runda/pregatire_rapida/clasament | Cod sursa (job #2220844) | Cod sursa (job #2811879) | Profil IacobTudor | Cod sursa (job #2488288)
// PotrivireaSirurilor.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
#include <algorithm>
std::ifstream fin("strmatch.in");
std::ofstream fout("strmatch.out");
int main()
{
std::string A = "", B = "";
int* v = new int[1000];
int hash = 0;
int sum = 0;
int app = 0;
fin >> A >> B;
int32_t m = A.length(), n = B.length();
if (m <= n) {
for (int i = 0; i < m; i++)
{
hash += int(A[i]);
sum += int(B[i]);
}
for (int i = m - 1; i < n; i++) {
if (i >= m)
sum += int(B[i]);
if (sum == hash)
if (B.substr(i - m + 1, m) == A) {
if (app <= 1000)
v[app] = i - m + 1;
app++;
}
sum -= int(B[i - m + 1]);
}
}
fout << app << std::endl;
if (app != 0 && m <= n) {
for (int i = 0; i < std::min(app, 1000); i++)
fout << v[i] << " ";
}
else fout << 0;
}