function TestNumber($N) { global $DecentNumber, $Max5s, $Max3s, $SolutionFound; switch ($N) { // Too small to start case $N <= 2: $SolutionFound = FALSE; $Max5s = 0; $Max3s = 0; $DecentNumber = "Special Case - Less than 3 digits - FAIL -1"; // For Testing, Change to -1 for final break; // Check for 3 - early success exit // Check for 3 - early success exit case $N == 3: $SolutionFound = TRUE; $Max5s = 1; $Max3s = 0; $DecentNumber = "Special Case Three Found - 555"; // For Testing, Change to -1 for final break; // Check for 4 - Fail // Check for 4 - Fail case $N == 4: $SolutionFound = FALSE; $Max5s = 0; $Max3s = 0; $DecentNumber = "Special Case = Equals 4 - FAIL -1"; // For Testing, Change to -1 for final break; // Check for Special Success MOD 3 = 0, If this is true, then we found a special case of all 5's. // Check for Special Success MOD 3 = 0, If this is true, then we found a special case of all 5's. case $N % 3 == 0: $SolutionFound = TRUE; $Max5s = $N / 3; $Max3s = 0; $DecentNumber = AssembleString($Max5s, $Max3s); break; default: $SolutionFound = FALSE; echo "Line {$N} - Not a Special Case - Looping it... \n"; GeneralCase($N); break; } }
// By the Contest Parameters, 1 <= $T <= 20 // Therefore we need an array to hold up to 20 values, and $T. // Declare Array to hold up to 20 values for the problem $FileArray = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); // Open Input File $SFile = fopen("php://stdin", "r") or die("Unable to open Input file!"); // Get first Record - The first record is the Number of records in the file to process $T = fgets($SFile); $FileArray[0] = $T; // Get the rest of the records $ppp = 1; while (!feof($SFile)) { $FileArray[$ppp] = fgets($SFile); $ppp += 1; } //End While // Close File fclose($SFile); // Open a file for writing $OutPutHandle = fopen("php://stdout", "w") or die("Unable to open Output file!"); // Reset the Output File to the Beginning, else an extra Linefeed gets injected. fseek($OutPutHandle, 0); // Main processing Loop, this is where we loop thru the records and solve each one for ($iii = 1; $iii <= $T; $iii++) { $ToPrint = GeneralCase($FileArray[$iii]) . "\n"; fwrite($OutPutHandle, $ToPrint); } //End For // Close the file for writing $OutPutHandle = fclose($OutPutHandle); // End Main
$FileArray[0] = $T; echo "Records to Read = " . $FileArray[0] . "<br>" . "\n"; $ppp = 1; while (!feof($SherlockFile)) { $FileArray[$ppp] = fgets($SherlockFile); echo $ppp . " - " . $FileArray[$ppp] . "<br>"; $ppp += 1; } //End While echo "<br>"; for ($x = 0; $x < 21; $x++) { echo $FileArray[$x]; echo ", "; } echo "<br>"; // Close File fclose($SherlockFile); echo "File Closed " . "<br>" . "\n"; for ($iii = 1; $iii <= $T; $iii++) { echo "Input # " . $FileArray[$iii] . "<br>" . "\n"; GeneralCase($FileArray[$iii]); // Use $iii for Testing all configs } //End For // End Main ?> </body> </html>