Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $bands = [];
- $bandsTime = [];
- while ($input !== "start of concert") {
- list ($command, $bandName, $players) = explode("; ", $input);
- if (!key_exists($bandName, $bands)) {
- $bands[$bandName][] = "";
- }
- if ($command === "Add") {
- $currPlayers = explode(", ", $players);
- for ($i = 0; $i < count($currPlayers);$i++){
- if (!in_array($currPlayers[$i], $bands[$bandName])) {
- $bands[$bandName][] = $currPlayers[$i];
- }
- }
- } else if ($command === "Play") {
- if (!key_exists($bandName, $bandsTime)) {
- $bandsTime[$bandName] = intval($players);
- } else {
- $bandsTime[$bandName] += intval($players);
- }
- }
- $input = readline();
- }
- uksort($bandsTime, function($key1, $key2) use ($bandsTime) {
- $time1 = $bandsTime[$key1];
- $time2 = $bandsTime[$key2];
- if ($time1 === $time2) {
- return $key1 <=> $key2;
- }
- return $time2 <=> $time1;
- });
- $bandNameToPrint = readline();
- echo "Total time: " . array_sum($bandsTime) . PHP_EOL;
- foreach ($bandsTime as $band => $time) {
- echo "$band -> $time" . PHP_EOL;
- }
- echo $bandNameToPrint . PHP_EOL;
- for ($i = 1; $i < count($bands[$bandNameToPrint]);$i++){
- echo "=> " . $bands[$bandNameToPrint][$i] . PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment