function check($data , $n){
$last0 = 0;
$first1 = 0;
$last2 = 0;
$first3 = 0;
$num = $data;
echo "\n\n";
for ($j=1; $j <= $n; $j++) {
# code...
$a = floor($num/pow(10, $n-$j));
if ($a>3) {
return 0;
}elseif (0==$a) {
$last0 = $j;
}elseif (1==$a) {
$first1 = (0==$first1) ? $j : $first1;
}elseif (2==$a) {
$last2 = $j;
}elseif (3==$a) {
$first3 = (0==$first3) ? $j : $first3;
}
$num = $num%pow(10, $n-$j);
echo "$a $last0,$first1,$last2,$first3 $num \n";
}
if ($last0>$first1 || $last2 > $first3) {
return 0;
}
if (0==$last0 || 0==$first1 || 0==$last2 || 0==$first3) {
return 0;
}
return $data;
}
function a($n){
$sum = 0;
for ($i=pow(10, $n-1); $i < pow(10, $n)-1; $i++) {
# code...
$result = check($i , $n);
if (0 != $result) {
# code...
$sum++;
// echo $i;
// echo "\t";
// echo $result;
if (0 == $sum%10) {
echo "\n";
}
}
}
echo $sum%1000000007;
}
PHP语言写的,没有C环境,就把变量名改改就能用