Last active
February 17, 2019 14:05
-
-
Save ilyosdev/1b96e4685f0647d4c5472bf2d79a3378 to your computer and use it in GitHub Desktop.
Solution for HackerRanks problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$_fp = fopen("php://stdin", "r"); | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
$text = $words = array(); | |
//collecting words as an array | |
while($in = fread($_fp,1024)){ | |
$text = array_merge($text, explode(' ', $in)); | |
} | |
$keywords = [ | |
'lol' => 1, | |
'rofl' => 2, | |
'lmao' => 3, | |
'lel' => 4 | |
]; | |
$words = array_count_values($text); | |
$points = 0; | |
foreach ($keywords as $keyword => $point) | |
{ | |
if (isset($words[$keyword])) | |
$points += $point * $words[$keyword]; | |
} | |
if($points<=5){ | |
echo "Patient has bright red face"; | |
}elseif($points>5 && $points<=12 ){ | |
echo "Patient is unable to speak"; | |
}elseif($points>12 && $points<=20){ | |
echo "Patient's sides are mildly bruised"; | |
}elseif($points>20 && $points<=31){ | |
echo "Patient has broken jaw, fractured ribs"; | |
}elseif($points>31 && $points<=49){ | |
echo "Patient is in a coma"; | |
}else{ | |
echo "Patient is dead"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!php