Cod sursa(job #2488031)

Utilizator FlorianMarcuMarcu Florian Cristian FlorianMarcu Data 6 noiembrie 2019 00:05:50
Problema Potrivirea sirurilor Scor 16
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
// 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;

}