Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

TSORT using PHP

$
0
0

I have written a very simple PHP script to try to solve the TSORT problem. I wouldn't be surprised at all if it timed out, but I don't know why I'm getting a "Wrong Answer" message. Can anyone tell me why or provide sample data that will cause the script to fail?

$count = 0;
$input = fopen('php://stdin', "r");
$output = fopen('php://stdout',"w");

$line1 = trim(fgets($input));
$test_cases = $line1[0];
$arr = array();

while($count < $test_cases){
    $val = trim(fgets($input));
    array_push($arr, $val);        
    $count++;
}

sort($arr);

foreach($arr as $val)  {
    echo $val . "\n";
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles