第一份PHP程序

<?php

    list($ncase) = fscanf(STDIN,"%d");

    $mod = 1000000007;

    for($n=0;$n<$ncase;++$n) {

        $x = 0;

        $od = 1;

        $ev = 0;

        list($str) = fscanf(STDIN,"%s");

        $len = strlen($str);

        $two = 1;

        $l = 0;

        $ans = 1;

        for($level=0;$level<$len;++$level) {

            $two = $two<<1;

            if ( $two>=$mod )

                $two -= $mod;

            if ( $str[$level]=="l" )

                $l = $l<<1;

            else

                $l = ($l<<1) | 1;

            if ( $l>=$mod )

                $l -= $mod;

            if ( $level & 1 ) {

            	$ans = (($od+1)<<1)+($l<<1)-1;

                $od += $two;

                if ( $od>=$mod )

                	$od -= $mod;

            } else {

            	$ans = (($ev+1)<<1)+($l<<1);

                $ev += $two;

                if ( $ev>=$mod )

                	$ev -= $mod;

            }

            if ( $ans>=$mod )

                $ans -= $mod;

        }

        fprintf(STDOUT, "%d\n",$ans%$mod);

    }

?>

  

你可能感兴趣的:(PHP)