Pagini recente » Cod sursa (job #1058017) | Cod sursa (job #41635) | Cod sursa (job #2982812) | Cod sursa (job #350244) | Cod sursa (job #1811164)
#include <iostream>
#include <fstream>
#include <queue>
#include <unordered_map>
using namespace std;
void ReadInput(string &foundText, unordered_map<string, bool> &words,
unsigned int &wordLength)
{
string word;
ifstream inputStream("abc2.in");
inputStream>> foundText >> word;
wordLength = word.size();
words[word] = 1;
while( !inputStream.eof() )
{
inputStream>> word;
if( !words[word] )
{
words[word] = true;
}
}
inputStream.close();
}
int SearchWoords(string &foundText, unordered_map<string, bool> &words,
unsigned int wordLength)
{
unsigned int countWords = 0;
unsigned int foundTextLength = foundText.size();
string text = "";
for( unsigned int index = 0; index <= foundTextLength; ++index )
{
if( text.size() < wordLength )
{
text += foundText[index];
}
else
{
if( words[text] )
{
++countWords;
}
text.erase(text.begin());
if( index != foundTextLength )
{
text += foundText[index];
}
}
}
return countWords;
}
int main()
{
unsigned int wordLength;
string foundText;
unordered_map<string, bool> words;
ReadInput(foundText, words, wordLength);
ofstream outputStream("abc2.out");
outputStream<< SearchWoords(foundText, words, wordLength);
outputStream.close();
return 0;
}