Add solution for 2016 Day 11
This commit is contained in:
1 parent
fc16b73a01
commit
5d44b9484f
3 files changed
+217
-9
No files matched your search
@@ -51,6 +51,21 @@ struct Helper
|
||||
t.erase(std::remove_if(t.begin(), t.end(), func), t.end());
|
||||
}
|
||||
|
||||
static std::vector<std::string_view> Split(const std::string& str, const std::string& delim)
|
||||
{
|
||||
std::vector<std::string_view> split;
|
||||
size_t pos = str.find(delim);
|
||||
size_t lastPos = 0;
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
split.emplace_back(std::string_view{str.c_str() + lastPos, pos - lastPos});
|
||||
lastPos = pos + delim.size();
|
||||
pos = str.find(delim, pos + delim.size());
|
||||
}
|
||||
split.emplace_back(std::string_view{str.c_str() + lastPos, str.size() - lastPos});
|
||||
return split;
|
||||
}
|
||||
|
||||
static bool StartsWith(const std::string_view& str, const std::string& prefix, size_t offset = 0)
|
||||
{
|
||||
return str.substr(offset, prefix.size()) == prefix;
|
||||
|
||||
Reference in new issue
Block a user