# 
# 
# My first attempt at a quiz, and my solution.  It ran the first time,
# no debugging.  I debug code like this in my head before I run it. :)
# 
# The thought "bresenham algorithm" kept popping into my head while
# coming up with a solution... since it keeps track of the error
# introduced so far in quantifying a slope and rectifies it as you go
# along.  I just modified it to be a sloped line with multiple segments.
# 
#!/usr/local/bin/perl -w
use strict;
$|++;

use List::Util qw(sum);
# sub sum { my $n = 0; $n += $_ for @_; $n }

sub fudge_numbers {
  my $digits_after_decimal = shift;
  die "missing data" unless @_;
  die "negative values not allowed" if grep $_ < 0, @_;

  my $scale = 10 ** $digits_after_decimal;
  my $points = 100 * $scale;

  my @points;
  while (@_) {
    ## sum(@points) + $points == original $points
    my $sum = sum(@_) || 1;
    my $thispoints = int($points * (shift) / $sum);
    push @points, $thispoints;
    $points -= $thispoints;
  }

  return map { $_ / $scale } @points;
}

while (<>) {
  print join(" ",fudge_numbers(split)), "\n";
}

