cxx17/cc13.cc

30 lines
633 B
C++

// 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");
}