Created
September 19, 2015 07:15
-
-
Save Naba0123/0ffa89926d5f3ecc8dc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 六村リオ | |
# コーヒーを$amount味見をする | |
function drinkCoffee($amount) | |
{ | |
global $water; | |
global $coffee; | |
// 味見をする量の方が多い場合は量は0となる | |
if ($water + $coffee < $amount) { | |
$water = 0; | |
$coffee = 0; | |
} else { | |
$t_water = $water - $amount * $water / ($water + $coffee); | |
$coffee -= $amount * $coffee / ($water + $coffee); | |
$water = $t_water; | |
} | |
} | |
// 変数 | |
$water = 0; | |
$coffee = 0; | |
// 入力行数 | |
$count = trim(fgets(STDIN)); | |
for ($i = 0; $i < $count; ++$i) { | |
// input command | |
$command = explode(' ', trim(fgets(STDIN))); | |
switch ($command[0]) { | |
case '1': | |
$water += $command[1]; | |
break; | |
case '2': | |
$coffee += $command[1]; | |
break; | |
case '3': | |
drinkCoffee($command[1]); | |
break; | |
default: | |
break; | |
} | |
} | |
// print concentration | |
$amount = ($water + $coffee == 0) ? 1 : $water + $coffee; | |
echo floor(100 * $coffee / $amount) . "\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment