Pagini recente » Arhiva de probleme | redsnow_2 | Cod sursa (job #2956514) | Arhiva de probleme | Cod sursa (job #104789)
Cod sursa(job #104789)
#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;
}