RosettaCodeData/Task/Ordered-words/D/ordered-words-1.d

21 lines
475 B
D
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
void main() {
2015-02-20 00:35:01 -05:00
import std.stdio, std.algorithm, std.range, std.string;
2013-04-10 16:57:12 -07:00
string[] result;
size_t maxLen;
2015-02-20 00:35:01 -05:00
foreach (string word; "unixdict.txt".File.lines) {
word = word.chomp;
immutable len = word.walkLength;
if (len < maxLen || !word.isSorted)
2013-04-10 16:57:12 -07:00
continue;
if (len > maxLen) {
result = [word];
maxLen = len;
} else
result ~= word;
}
2015-02-20 00:35:01 -05:00
writefln("%-(%s\n%)", result);
2013-04-10 16:57:12 -07:00
}