A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 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 (div; divisors) {
|
||||
const maybe = find(rest, div);
|
||||
if (maybe.length > best.length) {
|
||||
best = maybe;
|
||||
delim = div;
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.length++;
|
||||
if (done) {
|
||||
result[$ - 1] = rest.idup;
|
||||
return result;
|
||||
} else {
|
||||
const t = findSplit(rest, delim);
|
||||
result[$ - 1] = t[0].idup;
|
||||
rest = t[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable s = "a!===b=!=c";
|
||||
immutable divs = ["==", "!=", "="];
|
||||
writeln(multiSplit(s, divs).join(" {} "));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue