This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,7 +1,8 @@
import std.stdio, std.algorithm;
void main() {
import std.stdio, std.algorithm;
static struct T { string item; double weight, price; }
auto items = [T("beef", 3.8, 36.0),
T("pork", 5.4, 43.0),
T("ham", 3.6, 90.0),
@ -10,19 +11,16 @@ void main() {
T("brawn", 2.5, 56.0),
T("welt", 3.7, 67.0),
T("salami", 3.0, 95.0),
T("sausage", 5.9, 98.0)];
sort!q{a.price/a.weight > b.price/b.weight}(items);
T("sausage", 5.9, 98.0)]
.schwartzSort!q{ -a.price / a.weight };
auto left = 15.0;
foreach (it; items) {
foreach (it; items)
if (it.weight <= left) {
writeln("Take all the ", it.item);
if (it.weight == left)
return;
left -= it.weight;
} else {
writefln("Take %.1fkg %s", left, it.item);
return;
}
}
} else
return writefln("Take %.1fkg %s", left, it.item);
}