Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@donatj
Created April 7, 2011 02:19
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 donatj/906901 to your computer and use it in GitHub Desktop.
Save donatj/906901 to your computer and use it in GitHub Desktop.
Code Jam Example
#!/usr/bin/php -q
<?php
$handle = @fopen("B-large-practice.in", "r");
$count = fgets($handle);
for( $i = 1; $i <= $count; $i++ ) {
echo 'Case #' . $i . ': ' . implode(' ', array_reverse(explode(' ', trim(fgets($handle)))) ) . PHP_EOL;
}
#!/usr/bin/php -q
<?php
$handle = @fopen("A-large-practice.in", "r");
$count = fgets($handle);
for( $i = 1; $i <= $count; $i++ ) {
$c = fgets($handle);
fgets($handle);
$prods = explode( ' ', fgets($handle) );
$x = 0;
foreach( $prods as $prod ) {
$find = $c - $prod;
if( $find > 0 ) {
if( ( $j = array_search( $find, $prods ) ) !== false && $j != $x ) {
echo 'Case #' . $i . ': ' . (min($x,$j) + 1) . ' ' . (max($x,$j) + 1) . PHP_EOL;
break 1;
}
}
$x++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment