Advertisement
KeeganT

Word Solver

Feb 5th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. int lineCount=0;
  8. string words[10000];
  9. string hint;
  10.  
  11. void updateList()
  12. {
  13.     ifstream file("gtb.txt");
  14.     string text;
  15.     while(getline(file,text))
  16.     {
  17.         words[lineCount]+=text;
  18.         lineCount++;
  19.     }
  20.     file.close();
  21.     cout<<"Total Themes Available: "<<lineCount<<endl;
  22. }
  23.  
  24. void repeatCheck()
  25. {
  26.     string temp, repeatedWordsList="";
  27.     bool repeat=false;
  28.     for(int c=0;c<lineCount;c++)
  29.     {
  30.         for(int x=0;x<lineCount;x++)
  31.         {
  32.             temp=words[c];
  33.             if(temp==words[x]&&x>c)
  34.             {
  35.                 repeatedWordsList+=temp;
  36.                 repeatedWordsList+=", ";
  37.                 repeat=true;
  38.             }
  39.         }
  40.     }
  41.     if(repeat==true)cout<<"Repeated Words Found: "<<repeatedWordsList<<endl;
  42. }
  43.  
  44. int main()
  45. {
  46.     updateList();
  47.     repeatCheck();
  48.     while(hint!="end")
  49.     {
  50.         cout<<"Hint: ";
  51.         getline(cin,hint);
  52.         system("cls");
  53.         if(hint=="add")
  54.         {
  55.             string newTheme;
  56.             ofstream file("gtb.txt");
  57.             cout<<"Theme to be added: ";
  58.             getline(cin,newTheme);
  59.             for(int c=0;c<lineCount;c++)file<<words[c]<<endl;
  60.             file<<newTheme<<endl;
  61.             cout<<newTheme<<" has been added to the list!"<<endl;
  62.             file.close();
  63.             for(int c=0;c<lineCount;c++)words[c]="";
  64.             lineCount=0;
  65.             updateList();
  66.             repeatCheck();
  67.         }
  68.         else if (hint=="substr")
  69.         {
  70.             string substrHint="";
  71.             cout<<"What is the substring within the hint?: ";
  72.             getline(cin,substrHint);
  73.             system("cls");
  74.             for(int c=0;c<lineCount;c++)if(words[c].find(substrHint)!=string::npos)cout<<words[c]<<endl;
  75.         }
  76.         for(int c=0;c<lineCount;c++)
  77.         {
  78.             bool possibleWord=true;
  79.             int numOfSpaces=0;
  80.             int tempHSpace=hint.find(' ');
  81.             int tempWSpace=words[c].find(' ');
  82.             int tempHSpace2=hint.find(' ',tempHSpace);
  83.             int tempWSpace2=words[c].find(' ',tempWSpace);
  84.             if(tempHSpace!=-1&&tempWSpace!=-1&&tempHSpace2==-1&&tempWSpace2==-1)numOfSpaces=1;
  85.             else if(tempHSpace!=-1&&tempWSpace!=-1&&tempHSpace2!=-1&&tempWSpace2!=-1)numOfSpaces=2;
  86.             if(hint.length()==words[c].length())
  87.             {
  88.                 if(hint.find(' ')==string::npos&&words[c].find(' ')==string::npos)
  89.                 {
  90.                     for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=words[c][x])possibleWord=false;
  91.                     if(possibleWord==true)cout<<words[c]<<endl;
  92.                 }
  93.                 else if(numOfSpaces==1)
  94.                 {
  95.                     int hspace1=hint.find(' ');
  96.                     int wspace1=words[c].find(' ');
  97.                     if(hspace1==wspace1)
  98.                     {
  99.                         for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=' '&&hint[x]!=words[c][x])possibleWord=false;
  100.                         if(possibleWord==true)cout<<words[c]<<endl;
  101.                     }
  102.                 }
  103.                 else if(numOfSpaces==2)
  104.                 {
  105.                     int hspace1=hint.find(' ');
  106.                     int wspace1=words[c].find(' ');
  107.                     int hspace2=hint.rfind(' ');
  108.                     int wspace2=words[c].rfind(' ');
  109.                     if(hspace1==wspace1&&hspace2==wspace2)
  110.                     {
  111.                         for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=' '&&hint[x]!=words[c][x])possibleWord=false;
  112.                         if(possibleWord==true)cout<<words[c]<<endl;
  113.                     }
  114.                 }
  115.             }
  116.         }
  117.     }
  118. }
  119.  
  120. ///Ideas
  121. ///Undo last action (adding words)
  122. ///Delete specific words
  123. ///Create backup file (Just in case :])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement