Four is the number of letters in the ...: Difference between revisions
Four is the number of letters in the ... (view source)
Revision as of 06:01, 4 June 2020
, 3 years agoReduce memory usage
m (const correctness fix) |
m (Reduce memory usage) |
||
Line 140:
return result;
}
const char* words[] = {▼
"Four", "is", "the", "number", "of", "letters", "in", "the",▼
"first", "word", "of", "this", "sentence,"▼
size_t count_letters(const std::string& str) {
Line 156 ⟶ 151:
std::vector<std::string> sentence(size_t count) {
▲ static const char* words[] = {
▲ "Four", "is", "the", "number", "of", "letters", "in", "the",
▲ "first", "word", "of", "this", "sentence,"
};
std::vector<std::string> result;
result.reserve(count + 10);
size_t n = std::size(words);
for (size_t i = 0; i < n && i < count; ++i) {
|