Cod sursa(job #497391)

Utilizator The_DisturbedBungiu Alexandru The_Disturbed Data 2 noiembrie 2010 13:05:12
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
struct point
{
	char x[20];
	point *y;
};
char s[10000000],c[50000][20],x[20];
point *a[1000000],*pp;
int l,i,j,n,k,q,m,p,max;
int h(char s[20])
{
	int q=0;
	long long x=0;;
	float c;
	for(int i=0;i<strlen(s);i++)x=x*10+((int)s[i]-(int)'a'+1);
	q=(int)s[0];
	c=(sqrt(5)-1)/10;
	return (int)(m*(q*c-(int)(q*c)));
}
void intro(char ss[20])
{
	point *p;
	p=new point;
	int q;
	q=h(ss);
	if(q>max)max=q;
	strcpy(p->x,ss);
	p->y=a[q];
	a[q]=p;
}
int srch(char ss[20])
{
	int q;
	q=h(ss);
	point *p;
	p=a[q];
	while(p)
	{
		if(strcmp(p->x,ss)==0)return 1;
		p=p->y;
	}
	return 0;
}
int main()
{
	freopen("abc2.in","r",stdin);
	freopen("abc2.out","w",stdout);
	gets(s);
	m=50000/3;
	gets(c[0]);intro(c[0]);
	n=1;
	p=strlen(c[0]);
	while(!feof(stdin))
	{
		gets(c[n]);
		intro(c[n]);
		n++;
	}
	j=0;
	while(strlen(s))
	{
		strncpy(x,s,p);
		if(srch(x))j++;
		strcpy(s,s+1);
	}
	printf("%d\n",j);
	/*for(i=0;i<=max;i++)
	{
		pp=a[i];
		while(pp)
		{
			printf("%s   ",pp->x);
			pp=pp->y;
		}
		printf("\n");
	}*/
	
	return 0;
}