Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Longest-string-challenge/D/longest-string-challenge.d
Normal file
19
Task/Longest-string-challenge/D/longest-string-challenge.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import std.stdio, std.array;
|
||||
|
||||
/// Return a.length - b.length if positive, 0 otherwise.
|
||||
int longer(string a, string b) {
|
||||
while (!a.empty && !b.empty)
|
||||
a.popFront(), b.popFront();
|
||||
return a.length;
|
||||
}
|
||||
|
||||
void main() {
|
||||
string longest, lines;
|
||||
foreach (string line; stdin.lines())
|
||||
if (longer(line, longest))
|
||||
lines = longest = line;
|
||||
else if (!longer(longest, line))
|
||||
lines ~= line;
|
||||
|
||||
writeln(lines);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue