php$n = intvalfgetsSTDIN;$block = intvalsqrt$n;$output = ;for $b = 0; $b $block; $b++ $start = $b $block + 1; $end = $b + 1 $block + 1; for $i = $start; $i $end; $i++ $value = $i + 1 $i 1; $
这段代码中的问题是在将内容输出到标准输出时,使用了错误的参数。正确的方法是使用echo语句将内容直接输出到标准输出。修改后的代码如下:
$n = intval(fgets(STDIN));
$block = intval(sqrt($n));
$output = '';
for ($b = 0; $b < $block; $b++) {
$start = $b * $block + 1;
$end = ($b + 1) * $block + 1;
for ($i = $start; $i < $end; $i++) {
$value = (($i + 1) * $i) >> 1;
$output .= $value . "\n";
}
}
$start = $block * $block + 1;
$end = $n + 1;
for ($i = $start; $i < $end; $i++) {
$value = (($i + 1) * $i) >> 1;
$output .= $value . "\n";
}
echo $output;
这样修改后,代码将正确输出结果到标准输出
原文地址: http://www.cveoy.top/t/topic/iSIe 著作权归作者所有。请勿转载和采集!