Determine if a string is collapsible: Difference between revisions

m
Reformatted C++ code
m (Reformatted C++ code)
Line 465:
std::basic_string<char_type> collapse(std::basic_string<char_type> str)
{
auto i = std::unique(str.begin(), str.end());
str.erase(i, str.end());
return str;
}
 
void test(const std::string& str)
{
std::cout << "original string: <<<" << str << ">>>, length = " << str.length() << '\n';
std::string collapsed(collapse(str));
std::cout << "result string: <<<" << collapsed << ">>>, length = " << collapsed.length() << '\n';
std::cout << '\n';
}
 
int main(int argc, char** argv)
{
test("");
test("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ");
test("..1111111111111111111111111111111111111111111111111111111111111117777888");
test("I never give 'em hell, I just tell the truth, and they think it's hell. ");
test(" --- Harry S Truman ");
return 0;
}</lang>
 
Line 505:
result string: <<< - Hary S Truman >>>, length = 17
</pre>
 
 
=={{header|Clojure}}==
1,777

edits