add trick example of greatest-common-divisor, knuth-morris-pratt, primality-test, quick-pow, split-text
This commit is contained in:
13
trick/split-text.cpp
Normal file
13
trick/split-text.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::vector<std::string> split(std::string target, std::string pattern) {
|
||||
std::vector<std::string> res;
|
||||
size_t start = 0, next = 0;
|
||||
while ((next = target.find(pattern, start)) != std::string::npos) {
|
||||
res.push_back(target.substr(start, next - start));
|
||||
start = next + pattern.length();
|
||||
}
|
||||
res.push_back(target.substr(start));
|
||||
return res;
|
||||
}
|
Reference in New Issue
Block a user