Initial commit

This commit is contained in:
2021-12-01 20:31:53 +00:00
commit 2f44ccc3a7
106 changed files with 9333 additions and 0 deletions

37
2015/puzzle-08-02.cc Normal file
View File

@@ -0,0 +1,37 @@
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <variant>
std::string escape(std::string const &s) {
std::string escaped;
escaped += '"';
for (auto c : s) {
if (c == '\\' || c == '"') {
escaped += '\\';
}
escaped += c;
}
escaped += '"';
return escaped;
}
int main(int argc, char **argv) {
unsigned len = 0;
// Parse the input
for (std::string line; std::getline(std::cin, line);) {
std::string escaped = escape(line);
len += escaped.length() - line.length();
std::cout << line << ": " << line.length() << " memory bytes, "
<< escaped.length() << " escaped bytes, difference: "
<< escaped.length() - line.length() << "\n";
}
std::cout << len << "\n";
return 0;
}