Skip to content

Instantly share code, notes, and snippets.

@asteig
Created January 8, 2011 07:14
Show Gist options
  • Select an option

  • Save asteig/770636 to your computer and use it in GitHub Desktop.

Select an option

Save asteig/770636 to your computer and use it in GitHub Desktop.
Studious Student
<?php
//grab an array from input file
$handle = fopen("input.txt", "r");
$i = 0;
while (!feof($handle) ) {
$lines[$i] = trim(fgets($handle));
$i++;
}
fclose($handle);
$count = count($lines) - 1;
//alphabetize each line
for($i = 1; $i <= $count; $i++) {
$words = explode(" ", $lines[$i]);
unset($words[0]);
sort($words);
$words = implode($words);
print($words) . "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment