当前登录: 游客
玩儿 Google Code Jam
作者:water 地方: 北京 发布时间:2010-04-11 12:20:33 已经有152人阅读过
看原大图
March 14th
看原大图
Andersen
代码:


{water@test /tmp}$ php google.php A-small-practice.in

real 0m0.062s
user 0m0.044s
sys 0m0.018s

Case #45: 8448
Case #46: 2711
Case #47: 7753
Case #48: 2721
Case #49: 9326
Case #50: 8977

<?

if(! is_file($argv[1]) )
{
echo "Error Input File...\n";
exit(0);
}


$f = file($argv[1]);

foreach($f as $ff)
{
$arr[] = trim($ff);
}

if( $arr[0]*2 != (count($arr) - 1))
{
echo "Error Wrong Input File (Total Number of Lines)\n";
exit(-1);
}
else
{
$N = $arr[0];
for($i=1;$i<$N+1;$i++)
{
echo "Case #".$i.": ".
rtn_odd($arr[2*$i-1], $arr[2*$i])."\n";
}
}

function rtn_odd($t, $list)
{
$m = explode(" ",$list);

if($t != count($m) || ($t % 2) != 1)
{
echo "Error Data\n";
exit(-2);
}
sort($m);
for($i=0;$i<$t+1;$i+=2)
{
if($m[$i] != $m[$i+1])
{
$rest = $m[$i];
break;
}
}
return $rest;
}
?>



http://code.google.com/codejam/contest/dashboard?c=438101#

代码要有爱!

下个挑战:http://code.google.com/codejam/contest/dashboard?c=351101#
我最近发表的
社交网络
漂亮的妹妹
夏天 2011
PHP 日期计算方式
2011年6月
评论
No Comment at Moment
发表评论
用户名: 密码 昵称 匿名留言 我要记录