Pagini recente » Cod sursa (job #174910) | Cod sursa (job #1766612) | Cod sursa (job #1734239) | Cod sursa (job #1820866) | Cod sursa (job #2488031)
// PotrivireaSirurilor.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
#include <string>
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;
for (int i = 0 ; i < A.length(); i++)
{
hash += int(A[i]);
sum += int(B[i]);
}
for (int i = A.length() - 1; i < B.length(); i++) {
if (i >= A.length())
sum += int(B[i]);
if (sum == hash)
v[app++] = i - A.length() + 1;
sum -= int(B[i - A.length() + 1]);
}
if (app != 0) {
fout << app << std::endl;
for (int i = 0; i < app; i++)
fout << v[i] << " ";
}
else fout << 0;
}