Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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