SHARE
TWEET

Untitled

a guest May 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $input = explode(', ', readline());
  3. $towns = [];
  4. for ($i = 0, $j = 1; $i < count($input) - 1; $i += 2,$j += 2){
  5.     $town = $input[$i];
  6.     $income = $input[$j];
  7.     if (array_key_exists($town, $towns)){
  8.         $towns[$town] += $income;
  9.     }else{
  10.         $towns[$town] = $income;
  11.     }
  12. }
  13. foreach ($towns as $key => $value){
  14.     echo "$key => $value".PHP_EOL;
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top