Cod sursa(job #2589026)

Utilizator ViAlexVisan Alexandru ViAlex Data 25 martie 2020 18:00:27
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<bits/stdc++.h>
using namespace std;

ifstream in("abc2.in");
ofstream out("abc2.out");

string text;
int word_length;

unordered_set<string> words;


bool contains(const string& word){
	return words.find(word)!=words.end();
}

void read(){
	in>>text;
	string word;

	while(in>>word){
		words.insert(word);
	}

	word_length=word.length();

}


void solve(){

	string formed;
	int result=0;


	for(int i=0;i<text.length();i++){
		formed+=text[i];

		if(formed.length()==word_length){
			if(contains(formed))
				result++;

			formed=formed.substr(1,word_length-1);
		}

	}
	out<<result<<endl;
}



int main(){
	read();
	solve();
	return 0;
}