From: XinqiBao <35754562+XinqiBao@users.noreply.github.com> Date: Sun, 3 Mar 2019 04:12:00 +0000 (-0500) Subject: implemented set X-Git-Url: https://git.xinqibao.xyz/Wordscapes.git/commitdiff_plain/1b3007a06a0c1126af57e241287793ec8494e708?ds=sidebyside implemented set --- diff --git a/solution.cc b/solution.cc index 46fec60..b622a73 100644 --- a/solution.cc +++ b/solution.cc @@ -8,6 +8,7 @@ #include #include #include +#include using namespace std; class lset{ @@ -101,7 +102,7 @@ private: int numLetters; vector letters; int findWords(){ - cout << "Find words: blank as '*' || exit: 0 \n->"; + cout << "Find words: blank as '*' || back new scape: 0 \n->"; string str; cin >> str; if(str[0] == '0') @@ -127,13 +128,17 @@ private: } } int sizeW = word.size(); - finding(word, lstat, 0, sizeW, ""); + set ans; + finding(word, lstat, 0, sizeW, "", ans); + for(auto& w: ans) + cout << w << endl; return 0; } - void finding(vector w, vector lst, int pos, int ws, string str){ + void finding(vector w, vector lst, int pos, int ws, string str, set& ans){ if(pos == ws){ - if(dic.find(&(str+'\0')[0])) - cout << str << endl; + if(dic.find(&(str)[0])) + //cout << str << endl; + ans.insert(str); return; } if(pos != 0 && !dic.prefix(&(str+'\0')[0])) @@ -144,18 +149,18 @@ private: string st = str+letters[i];//cout <<'-'< lst_(lst); lst_[i] = true; - finding(w, lst_, pos+1, ws, st); + finding(w, lst_, pos+1, ws, st, ans); } } } else{ str += w[pos]; - finding(w, lst, pos+1, ws, str); + finding(w, lst, pos+1, ws, str, ans); } } public: scape(lset& dic): dic(dic){ - cout << "add letters || To exit: 0 \n->"; + cout << "add letters || back new scape: 0 \n->"; string str; cin >> str; if(str[0] == '0')