Cod sursa(job #1971699)

Utilizator Robert29FMI Tilica Robert Robert29 Data 20 aprilie 2017 21:00:28
Problema Potrivirea sirurilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include<stdio.h>
#include<string>
#include<fstream>
#include<vector>
using namespace std;
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");

struct result{
	int nr;
	vector<int> matches;
};

result GetMatches(string a, string b)
{
	result res;

	res.nr = 0;
	long long found = 0;
	do{
		found = b.find(a, found);

		if(found < b.length())
		{
			++res.nr;
			if(res.matches.size() < 1000)
			{
				res.matches.push_back(found);
			}
		}
		++found;
	}while(found < b.length());

	return res;
}

int main(){

	string a, b;
	cin >> a >> b;

	result res = GetMatches(a, b);

	cout << res.nr << endl;
	for(int i = 0; i < res.matches.size(); ++i)
	{
		cout << res.matches[i] << " ";
	}

	cin.close();
	cout.close();
	return 0;
}