Created
January 2, 2016 20:41
-
-
Save Daniyal-Javani/6011b45012411c416120 to your computer and use it in GitHub Desktop.
hackerrank.com
This file contains 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 | |
//https://www.hackerrank.com/challenges/cavity-map | |
$handle = fopen ("php://stdin","r"); | |
fscanf($handle,"%d",$n); | |
$grid = array(); | |
for($grid_i = 0; $grid_i < $n; $grid_i++) | |
fscanf($handle,"%s",$grid[]); | |
for ($i = 1; $i < $n -1 ; ++$i){ | |
for ($j = 1 ; $j < $n -1 ; ++$j){ | |
if ($grid[$i][$j] > $grid[$i - 1][$j] && | |
$grid[$i][$j] > $grid[$i + 1][$j] && | |
$grid[$i][$j] > $grid[$i][$j - 1] && | |
$grid[$i][$j] > $grid[$i][$j + 1]) { | |
$grid[$i][$j]='X'; | |
} | |
} | |
} | |
foreach ($grid as $value) { | |
echo $value."\n"; | |
} |
This file contains 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 | |
//https://www.hackerrank.com/challenges/game-of-thrones | |
$_fp = fopen("php://stdin", "r"); | |
fscanf($_fp,"%s",$pass); | |
$pass_array = str_split($pass); | |
$number_of_values = array_count_values($pass_array); | |
//print_r($number_of_values); | |
if(strlen($pass) % 2 == 1){ | |
$can_be_odd = True; | |
} else { | |
$can_be_odd = False; | |
} | |
foreach ($number_of_values as $value) { | |
if($value % 2 == 1){ | |
if($can_be_odd){ | |
$can_be_odd = False; //No longer can be odd! | |
} else { | |
echo 'NO'; | |
die(); | |
} | |
} | |
} | |
echo "YES"; |
This file contains 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 | |
//https://www.hackerrank.com/challenges/time-conversion | |
$handle = fopen ("php://stdin","r"); | |
fscanf($handle,"%s",$time); | |
$hh = substr($time, 0, 2); | |
if ($time[8] == 'P') { // For 12:00:00PM | |
if ($hh != 12){ | |
$hh += 12; | |
} | |
echo $hh.substr($time, 2, 6); | |
} else { | |
if ($hh != 12){ //For 12:00:00AM | |
echo substr($time, 0, 8); | |
} | |
else { | |
$hh = '00'; | |
echo $hh.substr($time, 2, 6); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment