Cod sursa(job #105958)

Utilizator tudalexTudorica Constantin Alexandru tudalex Data 18 noiembrie 2007 10:13:20
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Happy Coding 2007 Marime 0.66 kb
#include <stdio.h>
#include <string.h>
#include <string>
#include <set>

using namespace std;



set <string> cuv;
char s[10000100],
     a[50001][20];
string temp;
int i, l, lmax, j, n, sol, lt, d;
int main()
{
	freopen("abc2.in","r",stdin);
	freopen("abc2.out","w",stdout);
	gets(s);
	while (scanf("%s",a[++i])>0)
	{
		l = strlen(a[i]);
		temp = a[i];
		cuv.insert(temp);
		if (l>lmax) lmax = l;
	}
	
	n = i;
	for (i = 0; s[i] != '\0'; ++ i)
	{
		lt = 0;
		for (j = 0; j < lmax && s[j+i] != '\0'; ++ j)
		{
			temp[lt] = s[j+i];
 			temp[++lt] = '\0';	
			if (cuv.find(temp)!=cuv.end())
				++sol;
		}
	}
	printf("%d\n", sol);
}