国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 邏輯算法 > 正文

PHP 實現的字典序排列算法

2024-09-08 23:18:44
字體:
來源:轉載
供稿:網友

感謝 bird 告訴我 $_post[] 的用法。代碼如下:

<?php
if ($_post["perdata"] == "")
{
$_post["perdata"] = "1 2 3 4";
}

$data = chop (trim ($_post["perdata"]));
$a = explode (" ", $data);
sort ($a);
$data = implode (" ", $a);
?>

<?php
function nextpermu (&$c)
{
$s = sizeof ($c);
$i = $s - 1;

while ($i > 0)
{
if ($c[$i] > $c[$i-1])
{
$j = $s-1;
while ($c[$j] <= $c[$i-1])
$j--;
$t = $c[$i-1];
$c[$i-1] = $c[$j];
$c[$j] = $t;
//echo $i."-".$j."<br>";
for ($j=$s-1; $i < $j; $i++, $j--)
{
$t = $c[$i];
$c[$i] = $c[$j];
$c[$j] = $t;
}
return true;
}
$i--;
}

for ($i = 0, $j=$s-1; $i < $j; $i++, $j--)
{
$t = $c[$i];
$c[$i] = $c[$j];
$c[$j] = $t;
}
return false;
}
?>
<html>
<head>
<title>排列-字典法</title>
</head>
<body>
<form action="permutation.php" method="post">
<table>
<tr>
<td><input type="text" name="perdata"></td>
<td><input type="submit" value="排列"></td>
</tr>
</table>
</form>

<p>當前元素:<? echo $data; ?></p>

<table width="60%">
<tr>
<th width="50" bgcolor="yellow">序號</th>
<th bgcolor="eeeeff">排列</th>
</tr>
<?php
$num = 1;

do
{
?>
<tr>
<td align="center"><? echo $num; ?> </td>
<td><? echo implode (" ", $a); ?></td>
</tr>
<?php
$num++;
}
while (nextpermu ($a));
?>
</table>
</body>
</html>

商業源碼熱門下載www.html.org.cn

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 明光市| 东台市| 卓尼县| 伊金霍洛旗| 德州市| 普安县| 宁强县| 龙里县| 关岭| 平度市| 文成县| 武义县| 武夷山市| 张家口市| 沂水县| 永泰县| 孝义市| 游戏| 柳林县| 芦山县| 松阳县| 大港区| 溆浦县| 花莲县| 铜陵市| 安化县| 甘洛县| 寿光市| 沂水县| 恩施市| 松潘县| 昂仁县| 司法| 德昌县| 武冈市| 金乡县| 铁岭市| 保靖县| 辽中县| 赤壁市| 汶上县|