Created
December 17, 2014 12:51
-
-
Save elzup/062febbce147f83b1789 to your computer and use it in GitHub Desktop.
PHPで競技プログラミングのデバッグテンプレート ref: http://qiita.com/elzup/items/3a3e05d959b3db338bac
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
----- 0 ----- | |
40 | |
[0.01884ms] | |
----- 1 ----- | |
600 | |
[0.00381ms] | |
----- 2 ----- | |
60 | |
[0.00310ms] |
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
10 | |
4 | |
--- | |
200 | |
3 | |
--- | |
3 | |
20 |
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 | |
// {{{ get input module | |
// debug input file name | |
define('DEBUG_FILENAME', 'input.txt'); | |
/* first module start (setup $input) */ | |
if(file_exists(DEBUG_FILENAME)) | |
{ | |
$inputs = explode("\n---\n", file_get_contents(DEBUG_FILENAME)); | |
define('DEBUG', TRUE); | |
} else | |
{ | |
$inputs = array(file_get_contents('php://stdin')); | |
define('DEBUG', FALSE); | |
} | |
foreach ($inputs as $i => $input) { | |
if (DEBUG) { | |
echo "\n----- {$i} -----\n"; | |
$time_start = microtime(true); | |
} | |
solve($input); | |
if (DEBUG) { | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo sprintf("\n[%.5fms]", $time * 1000); | |
} | |
} | |
// }}} -end | |
function solve($input) { | |
list($a, $b) = explode("\n", trim($input)); | |
echo $a * $b . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment