Advertisement
KeeganT

Word Solver 2.0

Mar 8th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.69 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.         else if(hint=="remove")
  77.         {
  78.             string wordDelete;
  79.             string deletedWord;
  80.             ofstream file("gtb.txt");
  81.             cout<<"Theme to be removed: ";
  82.             getline(cin,wordDelete);
  83.             for(int c=0;c<lineCount;c++)
  84.             {
  85.                 if(words[c]!=wordDelete||words[c]==deletedWord)file<<words[c]<<endl;
  86.                 else if(words[c]==wordDelete)deletedWord=words[c];
  87.             }
  88.             cout<<wordDelete<<" has been removed from the list!"<<endl;
  89.             file.close();
  90.             for(int c=0;c<lineCount;c++)words[c]="";
  91.             lineCount=0;
  92.             updateList();
  93.             repeatCheck();
  94.         }
  95.         else if(hint=="undo")
  96.         {
  97.             cout<<"Your last action has been undone!"<<endl;
  98.         }
  99.         for(int c=0;c<lineCount;c++)
  100.         {
  101.             bool possibleWord=true;
  102.             int numOfSpaces=0;
  103.             int tempHSpace=hint.find(' ');
  104.             int tempWSpace=words[c].find(' ');
  105.             int tempHSpace2=hint.find(' ',tempHSpace);
  106.             int tempWSpace2=words[c].find(' ',tempWSpace);
  107.             if(tempHSpace!=-1&&tempWSpace!=-1&&tempHSpace2==-1&&tempWSpace2==-1)numOfSpaces=1;
  108.             else if(tempHSpace!=-1&&tempWSpace!=-1&&tempHSpace2!=-1&&tempWSpace2!=-1)numOfSpaces=2;
  109.             if(hint.length()==words[c].length())
  110.             {
  111.                 if(hint.find(' ')==string::npos&&words[c].find(' ')==string::npos)
  112.                 {
  113.                     for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=words[c][x])possibleWord=false;
  114.                     if(possibleWord==true)cout<<words[c]<<endl;
  115.                 }
  116.                 else if(numOfSpaces==1)
  117.                 {
  118.                     int hspace1=hint.find(' ');
  119.                     int wspace1=words[c].find(' ');
  120.                     if(hspace1==wspace1)
  121.                     {
  122.                         for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=' '&&hint[x]!=words[c][x])possibleWord=false;
  123.                         if(possibleWord==true)cout<<words[c]<<endl;
  124.                     }
  125.                 }
  126.                 else if(numOfSpaces==2)
  127.                 {
  128.                     int hspace1=hint.find(' ');
  129.                     int wspace1=words[c].find(' ');
  130.                     int hspace2=hint.rfind(' ');
  131.                     int wspace2=words[c].rfind(' ');
  132.                     if(hspace1==wspace1&&hspace2==wspace2)
  133.                     {
  134.                         for(int x=0;x<hint.length();x++)if(hint[x]!='.'&&hint[x]!=' '&&hint[x]!=words[c][x])possibleWord=false;
  135.                         if(possibleWord==true)cout<<words[c]<<endl;
  136.                     }
  137.                 }
  138.             }
  139.         }
  140.     }
  141. }
  142.  
  143. ///Ideas
  144. ///Undo last action (adding words)
  145. ///Delete specific words
  146. ///Create backup file (Just in case :])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement