app.d 557 B

1234567891011121314151617181920212223242526
  1. import std.stdio : writeln, stdin;
  2. import std.exception : enforce;
  3. import stats;
  4. void main(string[] args)
  5. {
  6. Stat[] stats;
  7. foreach (arg; args[1 .. $])
  8. {
  9. auto newStat = cast(Stat) Object.factory("stats." ~ arg);
  10. enforce(newStat, "Invalid statistics function: " ~ arg);
  11. stats ~= newStat;
  12. }
  13. for (double x; stdin.readf(" %s ", &x) == 1;)
  14. {
  15. foreach (s; stats)
  16. {
  17. s.accumulate(x);
  18. }
  19. }
  20. foreach (s; stats)
  21. {
  22. s.postprocess();
  23. writeln(s.result());
  24. }
  25. }