Advertisement
ShadowEmbrace

Gold Miner

Nov 12th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2.  
  3. $input = readline();
  4. $count = 0;
  5. $goldKarats = [];
  6.  
  7. while ($input !== 'stop') {
  8.     $gold[] = $input;
  9.     if ($count === 0 || $count % 2 === 0) {
  10.         if (!key_exists($gold[$count], $goldKarats)) {
  11.             $goldKarats[$gold[$count]] = 0;
  12.         }
  13.     } else {
  14.         $goldKarats[$gold[$count - 1]] += $gold[$count];
  15.     }
  16.     $input = readline();
  17.     $count++;
  18. }
  19.  
  20. foreach ($goldKarats as $gold => $karat) {
  21.     printf("%s -> %sK\n", $gold, $karat);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement