Cod sursa(job #422770)

Utilizator miticaMitica mitica Data 23 martie 2010 10:25:39
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
# include <stdio.h>
# include <string.h>

# define nmax 2000005

char a[nmax],b[nmax],*p;
int n,sol[1005],i;

int main()
{
	freopen("strmatch.in","r",stdin);
	freopen("strmatch.out","w",stdout);
	scanf("%s", &a);
	scanf("%s", &b);
	if (a[strlen(a)-1]=='\n') a[strlen(a)-1]='\0';
	if (b[strlen(b)-1]=='\n') b[strlen(b)-1]='\0';
	p=b;
	do{
		p=strstr(p,a);
		if (p-b<=strlen(b))
		{
			n++;
			sol[n]=p-b;
		}
		p++;
	  }while (p-b<=strlen(b) && n<1000);
	printf("%d\n", n);
	for (i=1;i<=n;i++)
		printf("%d ", sol[i]);
	return 0;
}