diff --git a/Ch 1.Arrays And Strings/3.URLify/URLify2.cpp b/Ch 1.Arrays And Strings/3.URLify/URLify2.cpp deleted file mode 100644 index e1d77c1..0000000 --- a/Ch 1.Arrays And Strings/3.URLify/URLify2.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include - -#include -using namespace std; -/* in this solution we are using C++ stl/std style */ -string URLify(const string &str) -{ - int spacesCnt = 0; - string res; - - for (auto &is : str) { - if (is == ' ') { - ++spacesCnt; - } - } -// cout << "# of spaces: " << spacesCnt << endl; - auto newSize = str.size() + 2*spacesCnt; - res.resize(newSize); - cout << " res new size is: " << res.size() << endl; - int is=0, ir=0; - while (is < str.size()) { - if (str[is] != ' ') { - res[ir] = str[is]; - } - else if (str[is] == ' ') { - res[ir++] = '%'; - res[ir++] = '2'; - res[ir] = '0'; - } - ++is; ++ir; - } - return res; -} - -int main() -{ - string s = URLify("This is John Smith"); - cout << " the new string is: " << s << endl; - return 0; -} diff --git a/Ch 12. C++/k_strings.txt b/Ch 12. C++/k_strings.txt deleted file mode 100644 index 809a725..0000000 --- a/Ch 12. C++/k_strings.txt +++ /dev/null @@ -1,10 +0,0 @@ -first line in file -second line in file -third -forth -fifth -sixth -seventh -eightth -nineth - diff --git a/Ch 12. C++/print_k_lines.cpp b/Ch 12. C++/print_k_lines.cpp deleted file mode 100644 index 6388343..0000000 --- a/Ch 12. C++/print_k_lines.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include - - -#include -#include -#include -using namespace std; - -void printKlines (const string &fn, int k) -{ - if (k <= 0){ - cout << "Error invalid K value " << endl; - return; - } - string line; - int cnt=0, first=0; ifstream ifs(fn); - vector output; - while(getline(ifs, line) && !line.empty()) { - if(cnt >= k) { - output[first] = line; - first = (first+1)%k; - } - else { - output.emplace_back(line); - ++cnt; - } - } - - int start = first; - for (int i=0; i< (cnt < k ? cnt : k); ++i, start = (start+1)%k) { - cout << output[start] << endl; - } - -} - -int main() -{ - string fn;// = "k_strings.txt"; - cout << "Type in the file name: " << endl; - cin >> fn; - - cout << "Type the number of K last lines to print: " << endl; - int k; - cin >> k; - printKlines(fn, k); - - return 0; -} diff --git a/Chapter-16-moderate/test_word_freq b/Chapter-16-moderate/test_word_freq deleted file mode 100644 index 0a6619e..0000000 --- a/Chapter-16-moderate/test_word_freq +++ /dev/null @@ -1,7 +0,0 @@ -aa bb cc aa dd aa -xxaa - -xx aa -yy -zz - diff --git a/Chapter-16-moderate/word_freq.cpp b/Chapter-16-moderate/word_freq.cpp deleted file mode 100644 index dc1934b..0000000 --- a/Chapter-16-moderate/word_freq.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -/*count freq - * - * - * - * @parmas: - * filename - the book file name to read the lines and words from - * word - the word to lookup for in the book - * @return value: - * integer - the number of occurences in the document - * - * Assumptions: - * word is a match even is upper case and lower case are not match - * the word maybe part of a line - * -*/ - -int countWordFreq(const string & fileName, const string &word) -{ - cout << "file path is: " << fileName << endl; - ifstream ifn(fileName); - static map wordFreq; - string tword; - transform(word.begin(), word.end(), tword.begin(), ::tolower); - - if (!wordFreq.empty()) { - cout << "wordFreq is not empty" << endl; - cout << wordFreq[word] << endl; - return wordFreq[word]; - } - - string line; - while (getline(ifn, line)) { - if(line.empty()) { continue; } - stringstream ss(line); - string w; - while(ss >> w) { - transform(w.begin(), w.end(), w.begin(), ::tolower); - wordFreq[w]++; - } - } - - return wordFreq[word]; -} - -int main() -{ - string fileName; - - cout << "type the book file (full path): " << endl; - cin >> fileName; - //cout << countWordFreq("../input/test_word_freq", "aa") << endl; - cout << countWordFreq(fileName, "aa") << endl; - - - return 0; -}