Skip to content

Instantly share code, notes, and snippets.

@Naba0123
Created September 19, 2015 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naba0123/0ffa89926d5f3ecc8dc3 to your computer and use it in GitHub Desktop.
Save Naba0123/0ffa89926d5f3ecc8dc3 to your computer and use it in GitHub Desktop.
<?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