Code of stjephan
<?php
// judging script error_reporting(0); include_once '../inc.max.php'; e_start(); // end judging script
function diex(){ e_stop(); echo "<br/><br/>Total times: ".e_current(); die; }
$beginingTime = time();
$sadrzaj = file ("deck.txt"); $org = $sadrzaj[0];
$len = strlen($org); $half = $len/2;
$resultString = result ($org);
$action = array ("C","S","F"); $checked = array ();
$nizovi = 0;
$higher = 0; $higherKey = ""; $keyLen = 0; $begin=array ("" => $org);
while (1) {
$result = array(); foreach ($begin as $key => $niz) { $checkTime = time()-$beginingTime; if ($checkTime>58) { echo "\n$higherKey".strlen($higherKey); diex(); } $nizovi++; if ($keyLen==0) $lastAction=""; else $lastAction = substr($key,$keyLen-1,1); switch ($lastAction) { case "C": $tmpKey = $key."F"; $tmpRes = flip($niz); checkResult($tmpRes,$tmpKey); break; case "F": $tmpKey = $key."C"; $tmpRes = cut($niz); checkResult($tmpRes,$tmpKey); break; case "S": default: $tmpKey = $key."C"; $tmpRes = cut($niz); checkResult($tmpRes,$tmpKey); $tmpKey = $key."F"; $tmpRes = flip($niz); checkResult($tmpRes,$tmpKey); } $tmpKey = $key."S"; $tmpRes = shufle($niz); checkResult($tmpRes,$tmpKey); } if (count($result)==0) { echo "\n$higherKey".strlen($higherKey); } $keyLen++; $begin = $result; }
function checkResult($tmpresult,$key) { global $resultString, $higher,$higherKey, $org, $result, $checked; if ($tmpresult==$resultString) { echo "$key".strlen($key); diex(); } if (!in_array($tmpresult,$checked)) { array_push ($checked,$tmpresult); $result[$key]=$tmpresult; }
$theSame = similar_text ($tmpresult,$resultString); if ($theSame>$higher) { $higher = $theSame; $higherKey = $key; } return 0; }
function cut ($str) { global $half; return substr($str,$half).substr($str,0,$half); }
function shufle ($str) { global $half, $len; $new = ""; for ($i=$half;$i<$len;$i++) { $new .= $str[$i].$str[$i-$half]; } return $new; }
function flip ($str) { return strrev($str); }
function result ($str) { global $len; $rez = array (); for ($i=0;$i<$len;$i++) array_push($rez,$str[$i]); sort ($rez); return implode ("",$rez); } ?>
Back to results
|
|