Cod sursa(job #1814285)

Utilizator rosuflaRosu Flaviu rosufla Data 23 noiembrie 2016 20:20:43
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

ifstream f("strmatch.in");
ofstream g("strmatch.out");

int main(){
	string a, b;
	getline(f,a);
	getline(f,b);

	unsigned int i = 0, j = 0;
	int v[1001];
	int count = 0;
	if (a.length() > b.length()) {
		g << "0\n";
		return (0);
	}
	while (b[i] != '\0' && a[j] != '\0') {
		while (a[j] != '\0' && b[i] != '\0' && b[i] == a[j]) {
			i++;
			j++;
		}
		if (j == (a.length()) && count < 1000) {
			v[count] = i - j;
			++count;
		}
		i = i - j + 1;
		j = 0;
	}

	g << count << "\n";
	for (int i = 0; i < count; ++i)
		g << v[i] << " ";
	g << "\n";
	f.close();
	g.close();
    return 0;
}