PLEASE HELP ME CONVERT C++ TO PYTHON
-
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;string laced; laced.resize(s1.size() + s2.size()); int i = 0, pos = 0; int size = std::min(s1.size(), s2.size()); // interlace common lengths substrings for ( ; i < size; ++i) { laced\[pos++\] = s1\[i\]; laced\[pos++\] = s2\[i\]; } // append the remainder of longer string if (s1.size() >= s2.size()) for ( ; i < s1.size(); ++i) laced\[pos++\] = s1\[i\]; else for ( ; i < s2.size(); ++i) laced\[pos++\] = s2\[i\]; return laced;
}
-
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;string laced; laced.resize(s1.size() + s2.size()); int i = 0, pos = 0; int size = std::min(s1.size(), s2.size()); // interlace common lengths substrings for ( ; i < size; ++i) { laced\[pos++\] = s1\[i\]; laced\[pos++\] = s2\[i\]; } // append the remainder of longer string if (s1.size() >= s2.size()) for ( ; i < s1.size(); ++i) laced\[pos++\] = s1\[i\]; else for ( ; i < s2.size(); ++i) laced\[pos++\] = s2\[i\]; return laced;
}
Sorry, but that's not how it works. We're not here to do your work for you. We'll help if you've got a specific question or problem.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;string laced; laced.resize(s1.size() + s2.size()); int i = 0, pos = 0; int size = std::min(s1.size(), s2.size()); // interlace common lengths substrings for ( ; i < size; ++i) { laced\[pos++\] = s1\[i\]; laced\[pos++\] = s2\[i\]; } // append the remainder of longer string if (s1.size() >= s2.size()) for ( ; i < s1.size(); ++i) laced\[pos++\] = s1\[i\]; else for ( ; i < s2.size(); ++i) laced\[pos++\] = s2\[i\]; return laced;
}
Adding to Dave's comment, you are asking a question about C++ and Python in a C# forum. That's not very clever.
-
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;string laced; laced.resize(s1.size() + s2.size()); int i = 0, pos = 0; int size = std::min(s1.size(), s2.size()); // interlace common lengths substrings for ( ; i < size; ++i) { laced\[pos++\] = s1\[i\]; laced\[pos++\] = s2\[i\]; } // append the remainder of longer string if (s1.size() >= s2.size()) for ( ; i < s1.size(); ++i) laced\[pos++\] = s1\[i\]; else for ( ; i < s2.size(); ++i) laced\[pos++\] = s2\[i\]; return laced;
}
Wrong forum.
Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
-
Sorry, but that's not how it works. We're not here to do your work for you. We'll help if you've got a specific question or problem.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak{ ("Let me see your code sir"); }
-
string laceStrings(const string& s1, const string& s2)
{
if (s1.empty())
return s2;
if (s2.empty())
return s1;string laced; laced.resize(s1.size() + s2.size()); int i = 0, pos = 0; int size = std::min(s1.size(), s2.size()); // interlace common lengths substrings for ( ; i < size; ++i) { laced\[pos++\] = s1\[i\]; laced\[pos++\] = s2\[i\]; } // append the remainder of longer string if (s1.size() >= s2.size()) for ( ; i < s1.size(); ++i) laced\[pos++\] = s1\[i\]; else for ( ; i < s2.size(); ++i) laced\[pos++\] = s2\[i\]; return laced;
}
Next time use Google & find write forum before posting questions. Found this one[^] from Github. And alternatively you could Code Rewrite[^]
thatraja
Please update this article Useful Reference Books, it's urgent for Q/A section