Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $count = 0;
- $goldKarats = [];
- while ($input !== 'stop') {
- $gold[] = $input;
- if ($count === 0 || $count % 2 === 0) {
- if (!key_exists($gold[$count], $goldKarats)) {
- $goldKarats[$gold[$count]] = 0;
- }
- } else {
- $goldKarats[$gold[$count - 1]] += $gold[$count];
- }
- $input = readline();
- $count++;
- }
- foreach ($goldKarats as $gold => $karat) {
- printf("%s -> %sK\n", $gold, $karat);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement