Cod sursa(job #98589)

Utilizator Adriana_SAdriana Sperlea Adriana_S Data 10 noiembrie 2007 14:49:34
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Happy Coding 2007 Marime 0.83 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <map>

using namespace std;

const int N_MAX = 10000010;
const int L_MAX = 22;
char s[N_MAX], word[L_MAX], ver[L_MAX];

map <string, int> words;

string kkt;
char buf[1048576];

int main()
{
	freopen("abc2.in", "r", stdin);
#ifndef _SCREEN_
	freopen("abc2.out", "w", stdout);
#endif

	setbuf(stdin, buf);

	int l1;

	fgets(s, sizeof(s), stdin);
	fgets(word, L_MAX, stdin);
	l1 = strlen(word) - 1;
	word[l1] = '\0';
	kkt = word;
	words[kkt] = 1;

	while (fgets(word, L_MAX, stdin)) {
		word[l1] = '\0';
		kkt = word;
		words[kkt] = 1;
	}

	int l = strlen(s) - 1, nrp = 0, i, j;

	for (i = 0; i <= l - l1; i ++) {
		for (j = i; j < (i + l1); j ++) {
			ver[j - i] = s[j];
		}

		kkt = ver;
		if (words[kkt]) {
			nrp ++;
		}
	}

	printf("%d\n", nrp);

	return 0;
}