Add a solution to cc13.

master
Michael Hope 6 years ago
parent 80a5f00ff3
commit 51d65976ef
  1. 29
      cc13.cc

@ -0,0 +1,29 @@
// 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");
}
Loading…
Cancel
Save