You are new here and you starts with medium problems? Try easy ones, just to realize how to server works. I didn’t test your code completely, but you have to read FAQ, especially section How does Codechef test whether my solution is correct or not, first
If your program starts by printing ‘Enter the number’ and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.
I am jimit and My username is “jimit_it”. I tried to solve below problems and I have written cod in PHP. Can you tell me why it is giving me wrong answer. I want to know where I am being wrong or what I am doing wrong.
Can any one tell me why I am getting wrong answer for problem CMB05 Problem - CodeChef ? I have written code in PHP. I have tested below code command line too. please let me know what is the problem with below code for mentioned problem.
<?php
$stdin = fopen('php://stdin', 'r');
//echo 'Please enter num. of test cases & num of plates:';
$testcaseCnt = fgets($stdin);
$numOfPlates = fgets($stdin);
$i = 0;
while ($i < $testcaseCnt) {
$inputArr = array();
$j = 0;
//echo 'Please enter plate names:';
while ($j < $numOfPlates) {
$input = fgets($stdin);
$inputArr[$j] = $input;
$j++;
}
if (count($inputArr) > 0) {
$result = opendDoor($inputArr);
echo $result;
} else {
echo "The door cannot be opened. \n\n";
}
$i++;
}
function opendDoor($inputArr)
{
$totalPlate = count($inputArr);
$plateArr = array();
$t=0;
$plateArr[] = array_shift($inputArr);
$remainArr = $inputArr;
$i = 0;
foreach ($inputArr as $input) {
$tempName = trim(end($plateArr));
$lastChar = substr($tempName, -1);
foreach ($remainArr as $iKey => $iVal) {
$firstChar = substr(trim($iVal), 0, 1);
if ($lastChar == $firstChar) {
$plateArr[] = $iVal;
unset($remainArr[$iKey]);
break;
}
}
$i++;
}
if ($totalPlate == count($plateArr)) {
return "Ordering is possible.\n\n";
} else {
return "The door cannot be opened.\n\n";
}
}
fclose($stdin);
exit(0);
?>