add trick example of greatest-common-divisor, knuth-morris-pratt, primality-test, quick-pow, split-text

This commit is contained in:
2025-09-23 11:25:26 +08:00
parent 57dd0e9440
commit 5368fcd277
5 changed files with 78 additions and 0 deletions

13
trick/split-text.cpp Normal file
View 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;
}