Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Wrote my own solution:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;sstream&gt; #include &lt;vector&gt; typedef std::pair&lt;std::pair&lt;std::string, std::string&gt;, std::pair&lt;std::pair&lt;std::string, std::string&gt;, std::pair&lt;std::string, std::string&gt;&gt;&gt; pairStringTrio; typedef std::pair&lt;std::string,std::pair&lt;std::string,std::string&gt;&gt; stringPairString; stringPairString longestCommonSubstring(const pairStringTrio&amp;); std::string strFindReplace(const std::string&amp;, const std::string&amp;, const std::string&amp;); int main(void) { std::string s1= "6 HUMAN ACTIONb", s2="8 HUMAN ACTIONd", s3="10 HUMAN ACTIONf"; pairStringTrio result = std::make_pair(std::make_pair(s1, "6"), std::make_pair(std::make_pair(s2, "8"), std::make_pair(s3, "10"))); stringPairString answer = longestCommonSubstring(result); std::cout &lt;&lt; '\"' &lt;&lt; answer.first &lt;&lt; "\"\t\"" &lt;&lt; answer.second.first &lt;&lt; "\"\t\"" &lt;&lt; answer.second.second &lt;&lt; '\"'; } stringPairString longestCommonSubstring(const pairStringTrio &amp;foo) { std::string longest; for(size_t start=0, length=foo.first.first.size()-1; start + length &lt;= foo.first.first.size();) { std::string s1_tmp = foo.first.first.substr(start, length); std::string s2_tmp = strFindReplace(s1_tmp, foo.first.second, foo.second.first.second); std::string s3_tmp = strFindReplace(s1_tmp, foo.first.second, foo.second.second.second); if (std::string::npos != foo.second.first.first.find(s2_tmp) &amp;&amp; std::string::npos != foo.second.second.first.find(s3_tmp)) { s1_tmp.swap(longest); ++length; } else ++start; } return std::make_pair(longest, std::make_pair(strFindReplace(longest, foo.first.second, foo.second.first.second), strFindReplace(longest, foo.first.second, foo.second.second.second))); } std::string strFindReplace(const std::string &amp;original, const std::string&amp; src, const std::string&amp; dest) { std::string answer=original; for(std::size_t pos = 0; (pos = answer.find(src, pos)) != answer.npos;) answer.replace(pos, src.size(), dest); return answer; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload