Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. <?php
  2. $inputs = intval(readline());
  3. $legionsWithActivity = [];
  4. $legionsWithSoldiers = [];
  5. for ($i = 0; $i < $inputs; $i++) {
  6. // $a = readline();
  7. $input = readline();
  8. preg_match('/(\d+)\s\=\s(.+)\s\-\>\s(.+)\:(\d+)/', $input, $command);
  9. $lastActivity = $command[1];
  10. $legionName = $command[2];
  11. $soldierType = $command[3];
  12. $soldierCount = $command[4];
  13. if (!key_exists($legionName, $legionsWithActivity)) {
  14. $legionsWithActivity[$legionName] = $lastActivity;
  15. $legionsWithSoldiers[$legionName] = [];
  16. }
  17. if (!key_exists($soldierType, $legionsWithSoldiers[$legionName])) {
  18. $legionsWithSoldiers[$legionName][$soldierType] = 0;
  19. }
  20. if ($lastActivity > $legionsWithActivity[$legionName]) {
  21. $legionsWithActivity[$legionName] = $lastActivity;
  22. }
  23. $legionsWithSoldiers[$legionName] [$soldierType] += $soldierCount;
  24.  
  25. }
  26. $command =readline();
  27. $strpos=strpos($command,"\\");
  28. if ($strpos!==false) {
  29. $commands = explode("\\", $command);
  30. $activity = intval($commands[0]);
  31. $solderType = $commands[1];
  32. uksort($legionsWithSoldiers, function ($a, $b) use ($legionsWithSoldiers, $solderType) {
  33. if ($legionsWithSoldiers[$a][$solderType] === $legionsWithSoldiers[$b][$solderType]) return strcasecmp($a, $b);
  34. return $legionsWithSoldiers[$b][$solderType] - $legionsWithSoldiers[$a][$solderType];
  35. });
  36. foreach ($legionsWithSoldiers as $key => $item) {
  37. if ($legionsWithActivity[$key] < $activity) {
  38. echo "$key -> $item[$solderType]\n";
  39. }
  40. }
  41. } else {
  42. $solderType = $command;
  43. uksort($legionsWithActivity, function ($a, $b)use($legionsWithActivity) {
  44. if ($legionsWithActivity[$a] === $legionsWithActivity[$b]) return strcasecmp($a, $b);
  45. return $legionsWithActivity[$b] - $legionsWithActivity[$a];
  46. });
  47. foreach ($legionsWithActivity as $key => $item) {
  48. if (key_exists($solderType, $legionsWithSoldiers[$key])) {
  49. echo "$item : $key\n";
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement