|
发表于 2017-10-31 15:36
来自手机
|
显示全部楼层
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=1, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
</head>
<body class="home blog">
<div class="header">
<form method="post" action="" target="_parent" >
以逗号分隔的20个数值(1-8)<input name="numbers" type="text" style="width:250px" placeholder='1,2,3' value='<?php echo $_POST["numbers"]; ?>'/></br>
四则运算结果<input name="result" type="text" style="width:250px" placeholder='3' value='<?php echo $_POST["result"]; ?>'/>
<input name="hcsubmit" type="submit" value="立即提交">
</form>
</div>
<div>
<?php
function sign(){
$i=mt_rand(1,4);
switch($i)
{
case 1:
return "+";
break;
case 2:
return "-";
break;
case 3:
return "*";
break;
default:
return "/";
}
}
//echo(sign());
?>
<?php
//echo $_POST["numbers"].$_POST["result"];
if ($_POST["numbers"]!="") {
$str=calculate();
if($str!=""){
echo($str);
}else{
echo("not found");
}
}
//$number="1,2,3";
function calculate(){
$number=$_POST["numbers"];
$result_get=$_POST["result"];
$arr=explode(",",$number);
//echo(count($arr));
for($n=0;$n<904000;$n++){
for($i=0;$i<count($arr);$i++){
if($i==0){
//echo($arr[$i]);
$number=$arr[$i];
}else{
$number.=sign().$arr[$i];
}
}
eval("\$result=$number;");
if ($result==$result_get){
//echo($result."=".$number);
return($result."=".$number);
}else{
//echo("No");
}
}
}
?>
</div>
</body></html>
php版的凑数算24点,来凑热闹啦,请大家多指导。 |
评分
-
1
查看全部评分
-
|