Uhh I practically solved it I think.. You just go through all horizontal matches and vertical matches.. Try out which words fits and then start entering them. Solve by elimination.. Whichever has the most chars and satisfies the other spots, gets placed in..
Now I didn't finish the filling it but I practically did the algorithms for getting the horizontal matches and vertical matches. It's now only a matter of filling in each one.
#include <windows.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <map>
std::vector<std::string> HLines, VLines, WordList, HPos, VPos;
void FillHorizontal(std::string FilePath)
{
std::string Line;
std::fstream hFile(FilePath.c_str(), std::ifstream::in | std::ifstream::binary);
while (getline(hFile, Line))
{
HLines.push_back(Line);
}
hFile.close();
}
void FillVertical()
{
int K = 0, L = 0;
std::vector<std::string> Result;
for (std::string::iterator it = HLines[0].begin(); it != HLines[0].end(); ++it, L = 0, ++K)
{
std::string Temp;
for (int J = K; J < HLines[L].size(); ++L)
{
Temp += HLines[L][J];
if (L + 1 == HLines.size())
{
VLines.push_back(Temp);
break;
}
}
}
}
std::string Copy(std::string Str, int FirstChar, int Count)
{
if (FirstChar <= 0)
FirstChar = 0;
else
FirstChar -= 1;
return Str.substr(FirstChar, Count);
}
int Pos(std::string Needle, std::string Haystack, int StartPos)
{
return Haystack.find(Needle, StartPos);
}
int RPos(std::string Needle, std::string Haystack, int StartPos)
{
return Haystack.rfind(Needle, StartPos);
}
std::vector<std::string> SplitString(std::string StrToSplit, int NumberOfPieces)
{
std::string Temp = StrToSplit;
std::vector<std::string> Result;
while(Temp.size())
{
Result.push_back(Temp.substr(0, NumberOfPieces));
Temp.erase(0, NumberOfPieces);
}
return Result;
}
std::vector<std::string> SplitString(std::string StringToSplit, std::string Delimiter)
{
std::vector<std::string> Result;
size_t Pos = StringToSplit.find_first_of(Delimiter);
while(Pos != std::string::npos)
{
if(Pos > 0)
{
Result.push_back(StringToSplit.substr(0, Pos));
}
StringToSplit = StringToSplit.substr(Pos + 1);
Pos = StringToSplit.find_first_of(Delimiter);
}
if(StringToSplit.length() > 0)
{
Result.push_back(StringToSplit);
}
return Result;
}
std::vector<std::string> Posibilities(std::vector<std::string>& Lines)
{
int Offset = 0;
std::vector<std::string> Result;
for (std::vector<std::string>::iterator it = Lines.begin(); it != Lines.end(); ++it)
{
std::vector<std::string> Temp = SplitString(*it, "#");
for (std::vector<std::string>::iterator iter = Temp.begin(); iter != Temp.end(); ++iter)
if (iter->size() > 1)
Result.push_back(*iter);
}
return Result;
}
void FillWordList(std::string WordListPath)
{
std::string Line;
std::fstream hFile(WordListPath.c_str(), std::ifstream::in | std::ifstream::binary);
while (getline(hFile, Line))
{
WordList.push_back(Line);
}
hFile.close();
}
bool WordMatch(std::string Word, std::string SecondWord, char IgnoreChar)
{
for (int I = 0; I < Word.size(); ++I)
{
if ((Word[I] != IgnoreChar) && (Word[I] != SecondWord[I]))
return false;
}
return true;
}
std::vector<std::string> WordScrape(std::string WordToCompare, std::vector<std::string> &ListOfWords)
{
std::vector<std::string> Result;
for (std::vector<std::string>::iterator it = ListOfWords.begin(); it != ListOfWords.end(); ++it)
{
if (WordToCompare.size() == it->size())
{
if (WordMatch(WordToCompare, *it, '.'))
{
Result.push_back(*it);
}
}
}
return Result;
}
std::vector<std::vector<std::string> > FindHMatches()
{
std::vector<std::vector<std::string> > HorizontalMatches;
for (std::vector<std::string>::iterator it = HPos.begin(); it != HPos.end(); ++it)
{
if (Pos(".", *it, 0) != -1)
{
HorizontalMatches.push_back(WordScrape(*it, WordList));
}
}
return HorizontalMatches;
}
std::vector<std::vector<std::string> > FindVMatches()
{
std::vector<std::vector<std::string> > VerticalMatches;
for (std::vector<std::string>::iterator it = VPos.begin(); it != VPos.end(); ++it)
{
if (Pos(".", *it, 0) != -1)
{
VerticalMatches.push_back(WordScrape(*it, WordList));
}
}
return VerticalMatches;
}
int main()
{
FillWordList("C:/Users/Brandon/Desktop/crossword/words.txt");
FillHorizontal("C:/Users/Brandon/Desktop/crossword/example0.unsolved");
FillVertical();
HPos = Posibilities(HLines);
VPos = Posibilities(VLines);
}
If I have some free time, just bump this thread.. If I see it, I'll finish the program if you don't. :P I did it on my break in class :l