Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Multisplit/D/multisplit.d
Normal file
38
Task/Multisplit/D/multisplit.d
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import std.stdio, std.array, std.algorithm;
|
||||
|
||||
string[] multiSplit(in string s, in string[] divisors) pure nothrow {
|
||||
string[] result;
|
||||
auto rest = s.idup;
|
||||
|
||||
while (true) {
|
||||
bool done = true;
|
||||
string delim;
|
||||
{
|
||||
string best;
|
||||
foreach (const div; divisors) {
|
||||
const maybe = rest.find(div);
|
||||
if (maybe.length > best.length) {
|
||||
best = maybe;
|
||||
delim = div;
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.length++;
|
||||
if (done) {
|
||||
result.back = rest.idup;
|
||||
return result;
|
||||
} else {
|
||||
const t = rest.findSplit(delim);
|
||||
result.back = t[0].idup;
|
||||
rest = t[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
"a!===b=!=c"
|
||||
.multiSplit(["==", "!=", "="])
|
||||
.join(" {} ")
|
||||
.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue