Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $playersCards = [];
- $cmd = explode(': ', readline());
- while ($cmd[0] !== 'JOKER') {
- $player = $cmd[0];
- $cards = explode(', ', $cmd[1]);
- if (!key_exists($player, $playersCards)) {
- $playersCards[$player] = [];
- }
- for ($i = 0; $i < count($cards); $i++) {
- if (!in_array($cards[$i], $playersCards[$player])) {
- $playersCards[$player][] = $cards[$i];
- }
- }
- $cmd = explode(': ', readline());
- }
- foreach ($playersCards as $player => $hand) {
- $sumCard = 0;
- $sumHand = 0;
- foreach ($hand as $card) {
- if (strlen($card) === 3) {
- $sumCard += 10;
- if ($card[2] === 'S') {
- $sumCard *= 4;
- } elseif ($card[2] === 'H') {
- $sumCard *= 3;
- } elseif ($card[2] === 'D') {
- $sumCard *= 2;
- }
- } else {
- for ($j = 0; $j < strlen($card); $j++) {
- if (is_numeric($card[$j])) {
- $sumCard += intval($card[$j]);
- } else {
- switch ($card[$j]) {
- case 'S':
- $sumCard *= 4;
- break;
- case 'H':
- $sumCard *= 3;
- break;
- case 'D':
- $sumCard *= 2;
- break;
- case 'J':
- $sumCard += 11;
- break;
- case 'Q':
- $sumCard += 12;
- break;
- case 'K':
- $sumCard += 13;
- break;
- case 'A':
- $sumCard += 14;
- break;
- }
- }
- }
- }
- $sumHand += $sumCard;
- $sumCard = 0;
- }
- echo "$player: $sumHand" . PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement