use strict; use warnings; use feature qw/say/; # https://yukicoder.me/problems/5 # my $input = "100 # 100 # 500 # "; my $input = <>; chomp $input; my $hash_ref; ( $hash_ref->{100}, $hash_ref->{25}, $hash_ref->{1} ) = split /\n/, $input; if ( $hash_ref->{1} >= 25 ) { my $move_up = int( $hash_ref->{1} / 25 ); $hash_ref->{25} += $move_up; $hash_ref->{1} -= $move_up * 25; } if ( $hash_ref->{25} >= 4 ) { my $move_up = int( $hash_ref->{25} / 4 ); $hash_ref->{100} += $move_up; # say $hash_ref->{100}; $hash_ref->{25} -= $move_up * 4; } if ( $hash_ref->{100} >= 10 ) { my $move_up = int( $hash_ref->{100} / 10 ); # $move_up = int ($move_up % 10); $move_up = int($move_up / 10); $hash_ref->{100} -= $move_up * 100; } # say $hash_ref->{1}; # say $hash_ref->{25}; # say $hash_ref->{100}; my $sum = 0; for my $n (1,25,100){ $sum += $hash_ref->{$n}; } say $sum;