Skip to content

Instantly share code, notes, and snippets.

@elzup
Created December 17, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elzup/062febbce147f83b1789 to your computer and use it in GitHub Desktop.
Save elzup/062febbce147f83b1789 to your computer and use it in GitHub Desktop.
PHPで競技プログラミングのデバッグテンプレート ref: http://qiita.com/elzup/items/3a3e05d959b3db338bac
----- 0 -----
40
[0.01884ms]
----- 1 -----
600
[0.00381ms]
----- 2 -----
60
[0.00310ms]
10
4
---
200
3
---
3
20
<?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