Find String In String Vector
Mar 5, 2015 at 1:59am UTC
This program is to solve a word maze and find the number of words in the maze from a dictionary file. The program runs, but stops by finding 1,2 and 3 letter words. For the life of me I cannot figure out why. The problem seems to be in the find statements (line 49 onwards) which executes but does not give the entire result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
vector <string> dict,forward,reverse;
string rag;
double i=0,j=0;
size_t found;
ifstream dict1;
dict1.open("Dictionary.txt" );
while (!dict1.eof())
{
getline(dict1,rag);
transform(rag.begin(), rag.end(), rag.begin(),::tolower);
dict.push_back(rag);
}
ifstream raghav;
raghav.open("dumpling2.txt" );
while (!raghav.eof())
{
getline(raghav,rag);
transform(rag.begin(), rag.end(), rag.begin(),::tolower);
forward.push_back(rag);
rag=string(rag.rbegin(),rag.rend());
reverse.push_back(rag);
}
i=0;
j=0;
while (i<forward.size())
{
while (j<dict.size())
{
if (dict[j].size()>2)
{
found=forward[i].find(dict[j]);
if (found!=string::npos)
{
cout<<"found word " <<dict[j]<<" line found " <<j<<" forward " <<found<<endl;
}
found=reverse[i].find(dict[j]);
if (found!=string::npos)
{
cout<<"found word " <<dict[j]<<" line found " <<j<<" reverse " <<found<<endl;
}
}
j++;
}
i++;
}
}
Last edited on Mar 6, 2015 at 2:36am UTC
Mar 5, 2015 at 2:01am UTC
The files Dumpling2.txt is a word maze file and Dictionary is a `dictionary file', cannot attach it here.
Topic archived. No new replies allowed.