Cod sursa(job #810162)

Utilizator raulstoinStoin Raul raulstoin Data 9 noiembrie 2012 19:34:39
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include<fstream>
#include<string>
#define nmax 2000005
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
char a[nmax],b[nmax];
int c[1005],k;
int main()
{
	f>>a>>b;
	int m=strlen(a),n=strlen(b),i,j=0;
	if(m>n)
		g<<0<<'\n';
	else
	{
		do
		{
			i=0;
			if(a[i]==b[j])
			{
				while(a[i]==b[j] && a[i] && b[j])
				{
					i++;
					j++;
				}
				if(i==m)
				{
					c[k++]=j-m;
					j=j-m+1;
				}
			}
			else
				j++;
			
		}while(j<n && k<1000);
		g<<k<<'\n';
		if(k)
		{
			for(i=0;i<k;i++)
				g<<c[i]<<' ';
			g<<'\n';
		}
	}
	f.close();
	g.close();
	return 0;
}