<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[split string into max number of pieces (dictionary)]]></title><description><![CDATA[<p>Hi,</p>
<p>i want to build the following algorithm:<br />
Given a string and a table of valid words split the string into max number of pieces such that each piece is a valid word in itself in the best possible way.</p>
<p>for input : thisisawesome<br />
and dictionary: [this, is, a, awe, we, some, awesome]<br />
possible output: [this is a we some, this is awe some, this is awesome]</p>
<p>my approach is to find all words from the dict in the input string and insert the beginning and length in a hash table, matches at the same position are stored in a std::set and ordered by length of the match...</p>
<p>any idea how to improve it?</p>
<pre><code>std::vector&lt;std::string&gt; match_best(const std::set&lt;std::string&gt; &amp;dict, const string &amp;str) {
	std::vector&lt;std::string&gt; words;
	std::unordered_map&lt;int, std::set&lt;int&gt;&gt; ht;
	int i = 0;

	for(auto it = dict.begin(); it != dict.end(); it++) {
		size_t j = -1;

		while((j = str.find(*it, j+1)) != std::string::npos) {
			auto it2 = ht.find(j);

			if(it2 != ht.end()) {
				it2-&gt;second.insert(it-&gt;length());
				ht.insert(std::make_pair(j, it2-&gt;second));
			}
			else {
				std::set&lt;int&gt; s = {static_cast&lt;int&gt;(it-&gt;length())};
				ht.insert(std::make_pair(j, s));
			}
		}
	}

	while(i &lt; str.length() &amp;&amp; ht.size() &gt; 0) {
		auto it = ht.find(i);

		if(it != ht.end()) {
			// try to use match with min. number of characters
			words.push_back(str.substr(it-&gt;first, *it-&gt;second.begin()));
			i += *it-&gt;second.begin();

            // remove the value from the std::set
			it-&gt;second.erase(it-&gt;second.begin());
			// if std::set is empty -&gt; delete key from hash table
			if(it-&gt;second.size() == 0) {
				ht.erase(it-&gt;first);
			}
		}
		else {
			if(words.size() == 0) {
				break;
			}

			// remove prev. match if no match for the rest string
			i -= words.back().size();
			words.pop_back();
		}
	}

	return words;
}

int main() {
	// your code goes here

	std::set&lt;std::string&gt; dict1 = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;};
	std::vector&lt;std::string&gt; words = match_best(dict1, &quot;thisisawesomesomea&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict2 = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;awesome&quot;};
	words = match_best(dict2, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict3 = {&quot;this&quot;, &quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;};
	words = match_best(dict3, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

    cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict4 = {&quot;this&quot;, &quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;thisisawesome&quot;};
	words = match_best(dict4, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

    cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict5 = {&quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;a&quot;};
	words = match_best(dict5, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/321353/split-string-into-max-number-of-pieces-dictionary</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 14:08:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321353.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Nov 2013 18:00:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Fri, 08 Nov 2013 18:00:08 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>i want to build the following algorithm:<br />
Given a string and a table of valid words split the string into max number of pieces such that each piece is a valid word in itself in the best possible way.</p>
<p>for input : thisisawesome<br />
and dictionary: [this, is, a, awe, we, some, awesome]<br />
possible output: [this is a we some, this is awe some, this is awesome]</p>
<p>my approach is to find all words from the dict in the input string and insert the beginning and length in a hash table, matches at the same position are stored in a std::set and ordered by length of the match...</p>
<p>any idea how to improve it?</p>
<pre><code>std::vector&lt;std::string&gt; match_best(const std::set&lt;std::string&gt; &amp;dict, const string &amp;str) {
	std::vector&lt;std::string&gt; words;
	std::unordered_map&lt;int, std::set&lt;int&gt;&gt; ht;
	int i = 0;

	for(auto it = dict.begin(); it != dict.end(); it++) {
		size_t j = -1;

		while((j = str.find(*it, j+1)) != std::string::npos) {
			auto it2 = ht.find(j);

			if(it2 != ht.end()) {
				it2-&gt;second.insert(it-&gt;length());
				ht.insert(std::make_pair(j, it2-&gt;second));
			}
			else {
				std::set&lt;int&gt; s = {static_cast&lt;int&gt;(it-&gt;length())};
				ht.insert(std::make_pair(j, s));
			}
		}
	}

	while(i &lt; str.length() &amp;&amp; ht.size() &gt; 0) {
		auto it = ht.find(i);

		if(it != ht.end()) {
			// try to use match with min. number of characters
			words.push_back(str.substr(it-&gt;first, *it-&gt;second.begin()));
			i += *it-&gt;second.begin();

            // remove the value from the std::set
			it-&gt;second.erase(it-&gt;second.begin());
			// if std::set is empty -&gt; delete key from hash table
			if(it-&gt;second.size() == 0) {
				ht.erase(it-&gt;first);
			}
		}
		else {
			if(words.size() == 0) {
				break;
			}

			// remove prev. match if no match for the rest string
			i -= words.back().size();
			words.pop_back();
		}
	}

	return words;
}

int main() {
	// your code goes here

	std::set&lt;std::string&gt; dict1 = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;};
	std::vector&lt;std::string&gt; words = match_best(dict1, &quot;thisisawesomesomea&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict2 = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;awesome&quot;};
	words = match_best(dict2, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict3 = {&quot;this&quot;, &quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;};
	words = match_best(dict3, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

    cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict4 = {&quot;this&quot;, &quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;thisisawesome&quot;};
	words = match_best(dict4, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

    cout &lt;&lt; '\n';

	std::set&lt;std::string&gt; dict5 = {&quot;is&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;a&quot;};
	words = match_best(dict5, &quot;thisisawesome&quot;);
	for_each(words.begin(), words.end(), [](std::string &amp;s){ cout &lt;&lt; s &lt;&lt; &quot; &quot;; });

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2364449</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364449</guid><dc:creator><![CDATA[febro]]></dc:creator><pubDate>Fri, 08 Nov 2013 18:00:08 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 07:42:43 GMT]]></title><description><![CDATA[<p>Yeah, on a first glimpse: make the printing <code>for_each</code> a function on its own <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
(I know you wanted something on the matching approach -- have to get the whole idea first...)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364538</guid><dc:creator><![CDATA[minastaros]]></dc:creator><pubDate>Sat, 09 Nov 2013 07:42:43 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 15:57:40 GMT]]></title><description><![CDATA[<p>febro schrieb:</p>
<blockquote>
<p>i want to build the following algorithm:<br />
Given a string and a table of valid words split the string into max number of pieces such that each piece is a valid word in itself in the best possible way.</p>
<p>for input : thisisawesome<br />
and dictionary: [this, is, a, awe, we, some, awesome]<br />
possible output: [this is a we some, this is awe some, this is awesome]</p>
<p>my approach is to find all words from the dict in the input string and insert the beginning and length in a hash table, matches at the same position are stored in a std::set and ordered by length of the match...</p>
<p>any idea how to improve it?</p>
</blockquote>
<p>Hi febro,</p>
<p>don't know whether my suggestion improve the algorithm. I'm not even sure, whether it fits Your requirement exactly.<br />
The idea is to run over the input, character for character, and look which word still match. Founding a word save its iterator to ' <code>result</code> ' - the longest fitting word wins.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;iterator&gt; // ostream_iterator&lt;&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;set&gt;

template&lt; typename C, typename I &gt;
typename C::const_iterator get_word( const C&amp; words, I&amp; from, I to )
{
    using namespace std;
    vector&lt; bool &gt; ok( words.size(), true );
    typename C::const_iterator result = words.end();
    for( size_t column = 0;; ++column, ++from )
    {
        bool found_something = false;
        vector&lt; bool &gt;::iterator on_off = ok.begin();
        for( typename C::const_iterator i_word = words.begin(); i_word != words.end(); ++i_word, ++on_off )
        {
            if( !*on_off )
                continue;
            if( column == i_word-&gt;length() )
            {
                result = i_word; // word found; save position
                *on_off = false;
            }
            else if( from == to || (*i_word)[column] != *from )
                *on_off = false; // mismatch
            else
                found_something = true;
        }
        if( !found_something || from == to )
            break;
    }
    return result;
}

template&lt; typename C, typename I &gt;
std::vector&lt; std::string &gt; match_best( const C&amp; dict, I from, I to )
{
    std::vector&lt; std::string &gt; result;
    for( typename C::const_iterator i
        ; (i = get_word( dict, from, to )) != dict.end(); ) // stops, if no matching word was found
        result.push_back( *i );
    return result;
}

int main() 
{
    using namespace std;
    const char* dict1_[] = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;}; 
    set&lt; string &gt; dict1( dict1_, dict1_ + sizeof(dict1_)/sizeof(*dict1_) );
    const string in = &quot;thisisawesomesomea&quot;;
    vector&lt; string &gt; words = match_best( dict1, in.begin(), in.end() );
    copy( words.begin(), words.end(), ostream_iterator&lt; string &gt;( cout &lt;&lt; &quot;&gt; &quot;, &quot; &quot; ) );
    cout &lt;&lt; endl;
    return 0;
}
</code></pre>
<p>best regards<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364603</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 09 Nov 2013 15:57:40 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 17:24:02 GMT]]></title><description><![CDATA[<p>Assuming that you are only interested in the split with the most pieces, here is a algorithm in potentially O(m*n) (m=Dictionary length, n=string length) after you replace the slow std::search with a better algorithm:</p>
<pre><code class="language-cpp">using std::begin;
using std::endl;

// Change to Boost's boyer_moore_horspool if you need a better complexity
template &lt;typename HaystackIter, typename Needle, typename Output&gt;
void search_all(HaystackIter first, HaystackIter last, Needle &amp;needle,
                Output out) {
  for (HaystackIter it = first;
       (it = std::search(it, last, begin(needle), end(needle))) != last;
       it += needle.size())
    *out++ = std::make_pair(it, &amp;needle);
}

template &lt;typename C, typename I, typename Value = typename C::value_type&gt;
std::vector&lt;Value&gt; match_best(const C &amp;dict, I from, I to) {
  std::vector&lt;std::pair&lt;I, Value const *&gt; &gt; events;
  for (auto &amp;d : dict)
    search_all(from, to, d, std::back_inserter(events));
  std::sort(begin(events), end(events));
  std::vector&lt;std::pair&lt;int, Value const *&gt; &gt; dp(
      to - from + 1, std::make_pair(std::numeric_limits&lt;int&gt;::min(), nullptr));
  dp[0].first = 0;
  for (auto &amp;e : events) {
    auto &amp;old_res = dp[e.first - from + e.second-&gt;size()];
    auto new_res = std::make_pair(dp[e.first - from].first + 1, e.second);
    old_res = std::max(old_res, new_res);
  }
  std::vector&lt;Value&gt; result(dp.back().first);
  int res_idx = result.size() - 1;
  for (size_t i = dp.size() - 1; i; i = i - dp[i].second-&gt;size())
    result[res_idx--] = *dp[i].second;
  return result;
}

int main() {
  using namespace std;
  vector&lt;string&gt; dict1{ &quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot; };
  const string in = &quot;thisisawesomesomea&quot;;
  vector&lt;string&gt; words = match_best(dict1, begin(in), end(in));
  copy(begin(words), end(words), ostream_iterator&lt;string&gt;(cout &lt;&lt; &quot;&gt; &quot;, &quot; &quot;));
  cout &lt;&lt; endl;
}
</code></pre>
<p>Output:</p>
<pre><code>&gt; this is a we some some a
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2364626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364626</guid><dc:creator><![CDATA[i am awesome!]]></dc:creator><pubDate>Sat, 09 Nov 2013 17:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 17:30:52 GMT]]></title><description><![CDATA[<p>Note: change lines 28 - 31 to</p>
<pre><code class="language-cpp">std::vector&lt;Value&gt; result(std::max(0,dp.back().first));
  int res_idx = result.size() - 1;
  for (size_t i = dp.size() - 1; res_idx &gt;= 0; i = i - dp[i].second-&gt;size())
    result[res_idx--] = *dp[i].second;
</code></pre>
<p>if you don't want to crash my program if a valid splitting is impossible.</p>
<p>Also, add</p>
<pre><code class="language-cpp">std::vector&lt;std::string&gt; match_best(std::set&lt;std::string&gt; const&amp; dict,
                                    std::string const&amp; in)
{
  return match_best(dict, begin(in) end(in));
}
</code></pre>
<p>so that you can use my function within your main.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364628</guid><dc:creator><![CDATA[i am awesome!]]></dc:creator><pubDate>Sat, 09 Nov 2013 17:30:52 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 20:50:05 GMT]]></title><description><![CDATA[<p>what is the complexity of you algorithm?</p>
<p>how about a trie algorithm?</p>
<pre><code>#define ALPHABET_SIZE 26

typedef struct node {
	bool found;
	bool visited;
	node *link[ALPHABET_SIZE];
}node;

int LETTER(char x) {
	if(islower(x)) {
		return static_cast&lt;int&gt;(x) - static_cast&lt;int&gt;('a');
	}
	return -1;
}

node *insert (node *root, char *string) {
	if (root == NULL) {
		root = new node();
		root-&gt;visited = false;
		root-&gt;found = false;

		for(int i = 0; i &lt; ALPHABET_SIZE; i++) {
			root-&gt;link[i] = NULL;
		}
	}
	if (*string == '\0') {
		root-&gt;found = true;
	}
	else {
		root-&gt;link[LETTER(string[0])] = insert(root-&gt;link[LETTER(string[0])], string+1);
	}

	return root;
}

void buildDictionary (node **root, std::vector&lt;std::string&gt; &amp;dict) {
	*root = NULL;

	for (auto it = dict.begin(); it != dict.end(); ++it) {
		*root = insert(*root, (char *) it-&gt;c_str());
	}
}

int find (node *root, std::string str, int index, std::vector&lt;std::string&gt; &amp;words) {
	if ((root == NULL) || (index == str.size() + 1)) {
		return 0;
	}

	if (!root-&gt;visited &amp;&amp; root-&gt;found) {
		words.push_back(str);
		words.back().resize(index);
		root-&gt;visited = true;
		return index;
	}
	else {
		return find (root-&gt;link[LETTER(str[index])], str, index+1, words);
	}
}

void cleanUp (node *root) {
	if (root == NULL) {
		return;
	}

	for (int i = 0; i &lt; ALPHABET_SIZE; i++) {
		cleanUp(root-&gt;link[i]);
	}

	delete root;
}

int main() {
	// your code goes here

	node *root = NULL;
	std::vector&lt;std::string&gt; dict = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;some&quot;, &quot;awesome&quot;}, words;
	std::string test = &quot;thisisawesome&quot;;
	buildDictionary (&amp;root, dict);
	int index = 0;

	while(index &lt; test.length()) {
		int val = find(root, &amp;test[index], 0, words);
		if(val &gt; 0) {
			index += val;
		}
		else {
			if(words.size() == 0) {
				break;
			}
			index -= words.back().size();
			words.pop_back();
		}
	}

	for (auto it = words.begin(); it != words.end(); ++it) {
		std::cout &lt;&lt; *it &lt;&lt; std::endl;
	}

	cleanUp(root);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2364667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364667</guid><dc:creator><![CDATA[febro]]></dc:creator><pubDate>Sat, 09 Nov 2013 20:50:05 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 21:07:58 GMT]]></title><description><![CDATA[<p>My algorithm runs in O(m*n*k) if there are m small strings with length of at most k and the big string to be splitted has length n. However, this can be easily converted to a O(m*(n+k)) = O(m*n) algorithm.</p>
<p>I tend to avoid tries as they usually exceed the memory limit by far and are in practice much slower even if they restrict the input to only lowercase letters.</p>
<p>Furthermore, you cannot use them here. Greedy approaches do not work. For example:</p>
<pre><code class="language-cpp">std::vector&lt;std::string&gt; dict = {&quot;ab&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;,&quot;g&quot;,&quot;a&quot;,&quot;bcdefg&quot;}, words;
  std::string test = &quot;abcdefg&quot;;
</code></pre>
<p>Produces</p>
<pre><code>a
bcdefg
</code></pre>
<p>with your code, but</p>
<pre><code>ab c d e f g
</code></pre>
<p>using my algorithm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364669</guid><dc:creator><![CDATA[i am awesome!]]></dc:creator><pubDate>Sat, 09 Nov 2013 21:07:58 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 21:26:48 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6765">@i</a> am awesome!<br />
your algorithm fails for the following dictionary: dict1{ &quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;awesome&quot; };</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364670</guid><dc:creator><![CDATA[febro]]></dc:creator><pubDate>Sat, 09 Nov 2013 21:26:48 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 21:39:52 GMT]]></title><description><![CDATA[<p>@febro: What would the result be?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364671</guid><dc:creator><![CDATA[i am awesome!]]></dc:creator><pubDate>Sat, 09 Nov 2013 21:39:52 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 21:45:58 GMT]]></title><description><![CDATA[<pre><code>std::vector&lt;std::string&gt; dict = {&quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;awe&quot;, &quot;we&quot;, &quot;awesome&quot;}, words;
    std::string test = &quot;thisisawesome&quot;;
</code></pre>
<p>output should be:<br />
this<br />
is<br />
awesome</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364672</guid><dc:creator><![CDATA[febro]]></dc:creator><pubDate>Sat, 09 Nov 2013 21:45:58 GMT</pubDate></item><item><title><![CDATA[Reply to split string into max number of pieces (dictionary) on Sat, 09 Nov 2013 21:58:22 GMT]]></title><description><![CDATA[<p>And whats <a href="http://ideone.com/7sD7Ee" rel="nofollow">exactly the problem</a>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2364673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2364673</guid><dc:creator><![CDATA[i am awesome!]]></dc:creator><pubDate>Sat, 09 Nov 2013 21:58:22 GMT</pubDate></item></channel></rss>