Cod sursa(job #98579)

Utilizator swift90Ionut Bogdanescu swift90 Data 10 noiembrie 2007 14:42:20
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Happy Coding 2007 Marime 0.75 kb
#include<stdio.h>
#include<string.h>
char cuv[50010][22],prop[10000010],aux[25];
int lun[50010];
int main(){
	freopen("abc2.in","r",stdin);
	freopen("abc2.out","w",stdout);
	int n,i,j,nr,x,s=0,ok;
	
	fgets(prop,10000010,stdin);
	n=strlen(prop)-1;
	i=0;
	while(fgets(aux,21,stdin)){
		ok=1;
		for(j=0;j<i && ok;++j){
			if(strcmp(aux,cuv[j])==0)
				ok=0;
		}
		if(ok){
			lun[i]=strlen(aux)-1;
			for(j=0;j<=lun[i];++j)
				cuv[i][j]=aux[j];
			++i;
		}
	}
	nr=i;
	for(i=0;i<n;++i){
		for(j=0;j<nr;++j){
			if(prop[i]==cuv[j][0]){
				ok=1;
				for(x=1;x<lun[j] && ok;++x){
					if(prop[i+x]!=cuv[j][x])
						ok=0;
				}
				if(ok)
					++s;
			}
		}
	}
	
	printf("%d\n",s);
	fclose(stdin);
	fclose(stdout);
	return 0;
}