Cod sursa(job #104789)

Utilizator vlad3rsterian vladut vlad3r Data 16 noiembrie 2007 18:03:56
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Happy Coding 2007 Marime 0.86 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void)
{
	char *v,*dic,*aux,*vcopy;
	int *este;
	long long nr,i;
	FILE *in,*out;

	in=fopen("abc2.in","r");
	out=fopen("abc2.out","w");
	
	v=(char *)malloc(10000002*sizeof(char));
	fgets(v,10000001,in);
	v[strlen(v)-1]='\0';
	printf("%s\n",v);

	dic=(char *)malloc(22*sizeof(char));
	este=(int *)malloc(strlen(v)*sizeof(int));

	for(i=0;i<strlen(v);i++)
		este[i]=0;
	nr=0LL;
	while(fgets(dic,22,in)!=NULL)
	{
		dic[strlen(dic)-1]='\0';
		printf("%s\n",dic);
		aux=v;
		vcopy=v;
		while((aux=strstr(vcopy,dic))!=NULL)
		{
			if(este[strlen(vcopy)-strlen(aux)]==0)
			{
				nr++;
				este[strlen(vcopy)-strlen(aux)]=1;
			}
		vcopy=aux+1;
		}
	
	}
	fprintf(out,"%lld",nr);
	//free(aux);
	free(v);
	free(este);
	free(dic);
	fclose(in);
	fclose(out);


	return 0;
}