emotrend

Vapor winter sale

Jan 4th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <?php
  2.  
  3. $input = explode(", ", readline());
  4.  
  5. $games = [];
  6. $gamesWithDlc = [];
  7. for ($i = 0; $i < count($input);$i++){
  8. if (strstr($input[$i], "-")) {
  9. list($gameName, $price) = explode("-", $input[$i]);
  10.  
  11. if (!key_exists($gameName, $games)) {
  12. $games[$gameName]['price'] = floatval($price);
  13. }
  14. } else if (strstr($input[$i], ":")) {
  15. list($gameName, $dlc) = explode(":", $input[$i]);
  16.  
  17. if (key_exists($gameName, $games)) {
  18. $games[$gameName]['dlc'] = $dlc;
  19. $games[$gameName]['price'] = ($games[$gameName]['price'] * 0.2) + $games[$gameName]['price'];
  20. }
  21. }
  22. }
  23.  
  24. foreach ($games as $gameName => $stats) {
  25. if (key_exists("dlc", $stats)) {
  26. $games[$gameName]['price'] = $games[$gameName]['price'] - ($games[$gameName]['price'] * 0.5);
  27. $gamesWithDlc[$gameName] = $games[$gameName];
  28. unset($games[$gameName]);
  29. } else {
  30. $games[$gameName]['price'] = $games[$gameName]['price'] - ($games[$gameName]['price'] * 0.2);
  31. }
  32. }
  33.  
  34. uksort($gamesWithDlc, function($key1, $key2) use ($gamesWithDlc) {
  35. return $gamesWithDlc[$key1]['price'] <=> $gamesWithDlc[$key2]['price'];
  36. });
  37. uksort($games, function($key1, $key2) use ($games) {
  38. return $games[$key2]['price'] <=> $games[$key1]['price'];
  39. });
  40.  
  41. foreach ($gamesWithDlc as $gameName => $stats) {
  42. $currDlc = $stats['dlc'];
  43. $currPrice = number_format($stats['price'], 2, ".", ".");
  44. echo "$gameName - $currDlc - $currPrice" . PHP_EOL;
  45. }
  46.  
  47. foreach ($games as $gameName => $stat) {
  48. $currPrice = number_format($stat['price'], 2, ".", ".");
  49. echo "$gameName - $currPrice" . PHP_EOL;
  50. }
Add Comment
Please, Sign In to add comment