Playing with C++17 via solving "Cracking the Coding Interview" questions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cxx17/cc13.cc

29 lines
633 B

// Determine if a string has all-unique characters.
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <string>
#include <fmt/format.h>
std::string urlify(std::string orig, int length) {
// Start writing at the back of the string.
auto write = orig.end();
for (auto read = orig.begin() + length; read != orig.begin();) {
read--;
if (*read == ' ') {
*--write = '0';
*--write = '2';
*--write = '%';
} else {
*--write = *read;
}
}
return std::string(write, orig.end());
}
TEST_CASE("cc13", "urlify") {
REQUIRE(urlify("Mr John Smith ", 13) == "Mr%20John%20Smith");
}