Words from neighbour ones: Difference between revisions
C++ code efficiency improvement
(C code efficiency improved) |
(C++ code efficiency improvement) |
||
Line 187:
=={{header|C++}}==
{{libheader|Boost}}
<lang cpp>#include <algorithm>
#include <cstdlib>
Line 194 ⟶ 195:
#include <string>
#include <vector>
#include <boost/circular_buffer.hpp>
// The input file must consist of one word per line in alphabetical order.
int main(int argc, char** argv) {
const int min_length = 9;
Line 204 ⟶ 207:
}
std::string line;
while (getline(in, line)) {▼
if (line.size() >= min_length)▼
words.push_back(line);▼
std::string previous_word;
int count = 0;
▲ while (getline(in, line)) {
for (size_t i = 0, n = words.size(); i + min_length <= n; ++i) {▼
continue;
continue;
std::string word;
word.reserve(min_length);
for (size_t
word += words[i
if (previous_word == word)
continue;
auto
if (
std::cout << std::setw(2) << ++count << ". " << word << '\n';
previous_word = word;
|