【问题标题】:Roman Transliteration: multiple alternates of single English letter, permutation and combination罗马音译:单个英文字母的多个替代,排列组合
【发布时间】:2020-04-01 15:10:15
【问题描述】:

我需要超排列的帮助

我有 3 个字母长的字符串“fhd”我想写每个交替 在信德语中,但问题是信德语有多种 以上每个字母的替代品

所以我有 3 个列表框,每个列表框用于每个字母在信德语中的替代品 一个用于信德语的改变每个字符串字母的字母和声音 "fhd"

f 列表框有 3 个项目(f 的替代项),它们是 ف، ڦ، په 所以列出一个 表示 F 的替代项,它们是`=ف، ڦ، په items

列出两个有 ح، ه، ھ 的 h

列表 3 有 D 的 د، ڏ، ڊ 替代项

目标是生成尽可能多的单词,所有单词都包含三个 信德替代字母包含 3 个信德字母作为替代 英语'fhd'

我的路径是什么,总是写f的第一个替代列表框f (第一个列表框)项目计数

并且在第二侧,所有其他字母都应表示一次

对于 h=0 到 len {fahad}

第一组为 a=ف b=ه c=د 第二组为 a=ف b=ح c=ڊ 第三组为 a=ف b=ه c=ڏ، 我们造的词是فهد فحڊ فهڏ

你注意到ف重复了三次直到第三个字母 d د، ڊ، ڏ的交替写了三遍

第二组词应该是 ڦهد ڦحڊ ڦهڏ 这里也是第二 作为alternate of的用法,fڦ的alternate被重复了三遍 D ڊ، ڏ، د 现在第二个字母 h 的替代(两个)每个 应该重复三次,我的意思是重点是第二个字母 h 交替 فهد ڦهڊ فهڏ

然后第二个交替的重复三遍

فحد فحڊ فحڏ

然后是 d=د فهد ڦحد فهد 的第一个替代项

然后是 d=ڊ،的第二个替换

فهڊ ڦحڊ فهڊ 然后是 d=ڏ 的第三个替代

فهڏ فهڏ فهڏ ڦهڏ

实际上我想在这种情况下建立罗马音译 多个英文字母的变体

我在要查询的背景中有信德语单词数据库 所有 fhd 的信德语替代词,哪一个可以写在 db 中 那一个在句子中替换了可以制作为的单词列表 fhd 的替代品应该是

فهد فحڊ فهڏ

带入的意思

فهد فهڊ فهڏ

あううううううか

فهد فهد فهد

ㄧㄧㄧㄧㄧㄧㄧㄧ

فهڏ ڦحڏ فهڏ 这是我想要的清单,谁能帮我怎么做 它以编程方式

我做了小飞机,但似乎不工作,可以任何或许多可能 将idea转化为真正的php编程

这是我为填充列表框所做的编程

<?php

        global $servername;
            global $username;
            global $password;
            global $dbname;


        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "tsrs";
        //////////////////////

        global $q;
        $q=array();

        //////////////////////
        for ($n=0; $n<=strlen("fahad"); $n++){

        $i=substr("fahad", $n, 1);
        //echo $i;

        /////////////////////
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
           die("Connection failed: " . $conn->connect_error);
        } 
        mysqli_set_charset($conn,"utf8");
        $sql = "SELECT * FROM duplicate WHERE engletter='$i' order by id";
        $result = $conn->query($sql);
        global $m;
        $m=1;

        if ($result->num_rows > 0) {
        $altrntcount=$result->num_rows; 


            while($row = $result->fetch_assoc()) {
            $q[$n][$m]=$row['sinletter']    ;
            echo $q[$n][$m]."<BR>";

            $m=$m+1;
            }
            }

        }
        echo "<form>";

        for ($n=0; $n<=strlen("fahad"); $n++){
        $list[$n]="list".$n;
        echo $list[$n];
        echo "
        <select name=\"".$list[$n]."\">";

        for ($m=0; $m<=$altrntcount; $m++){
        if ($q[$n][$m]<>""){
        echo "<option value=\"".$q[$n][$m]."\">".$q[$n][$m]."</option>";

        }

        }
        echo "</select>";
        }
        echo "</form>";

    ?>

    here is the further idea way but needs logical help to run


        for n-0 to len(fhd)

        for  x=0 to 5   loop...... the maximum alternates of any english letter in sindhi are 5

        for w=0 to len(fhd)
        for m-0 to 5 looop
        if m=>list(w).countitems then
        h=0
        word(q)(c)=word(q)(c)+list(w).selectedindex=h
        h=h+1
        end if
        //m=m+1

        w=w+1
        loop
        loop

        if m=>5 then
        x=x+1
        end if
        if w=>len(fhd)
        n=n+1

        end if
        if x=>list(n).countitems then
        p=0

        word(q)=word{q}+list(n).selectedindex=p
        p=p+1
        end if

        loop
        loop

【问题讨论】:

  • 如果第一个字母有 3 个选项,第二个字母有 2 个选项,第三个字母有 3 个选项,那么组合的数量是 3*2*3 = 18,这很简单,参见例如here for php 和这里 for SQL。您只得到/想要 7 个结果,但并不清楚为什么,所以如果有其他规则(假设除了您在问题中指定的内容之外,我们对信德字母一无所知),您可以计算所有组合和筛选出不正确的,或者让你的问题更清楚。
  • 如果信德字母没有什么特别之处,更多的是关于如何生成一般的组合,如果你用例如替换字母可能有助于使你的问题更具可读性。 "A","B","C" or "1","2","3",... 例如,即使您的列表中有一个非常明显的逻辑可以解释为什么它是 7 而不是18 种组合,至少我可能看不到,因为所有字母看起来都非常相似。参见例如第一个链接,操作员可能实际上并不想在他的实际问题中将 A1 与 B1 结合起来,但它使问题更容易理解。
  • Solarflare ؛我手头有数据库,其中包含几乎 90% 的信德语单词……所以如果我在 fhd 情况下查询所有可能的单词,长度限制为 3 个字符,那么我可以搜索我的数据库中所有可能的单词。和数据库有正确的词我会用正确的选择代表它فهد
  • stackoverflow.com/questions/59235326/…这个问题的答案也可以解决我的问题....你也可以看到这样的问题

标签: php mysql permutation superpermutation


【解决方案1】:

按两次或三次提交按钮,如何解决它是另一回事,但我在信德交替中找到了单词“fahad”字符串的所有排列

<?php 


global $servername;
    global $username;
    global $password;
    global $dbname;


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tsrs";
//////////////////////

global $q;
$q=array();

//////////////////////
for ($n=0; $n<=strlen("fahad"); $n++){

$i=substr("fahad", $n, 1);
//echo $i;

/////////////////////
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
} 
mysqli_set_charset($conn,"utf8");
$sql = "SELECT * FROM duplicate WHERE engletter='$i' order by id";
$result = $conn->query($sql);
global $m;
$m=0;

if ($result->num_rows > 0) {
$altrntcount=$result->num_rows; 


    while($row = $result->fetch_assoc()) {
    $q[$n][$m]=$row['sinletter']    ;
    echo $q[$n][$m]."<BR>";

    $m=$m+1;
    }
    }

}
echo "<form method='post'>";

for ($n=0; $n<=strlen("fahad")-1; $n++){
$list[$n]="list".$n;
echo $list[$n];
echo "
<select name=\"".$list[$n]."\" id=\"".$list[$n]."\">";

for ($m=0; $m<=$altrntcount-1; $m++){
if ($q[$n][$m]<>""){
echo "<option value=\"".$q[$n][$m]."\">".$q[$n][$m]."</option>";

}

}
echo "</select>";  
}?> 
<input type="text" name="leng" id="leng" value="1" ><input type='submit' name='submit'></form>
<?php 
if(isset($_POST['submit'])){

for($i=0; $i<=strlen("fahad")-1; $i++){

    //echo $list[$i]; 





for ($x=0; $x<= $_POST['leng']+1; $x++){

    ?>

    <script>



    document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;

 </script>
 <?php

    echo $i."-i: I : ".$x.": X <BR>";

    echo $q[$i][$x];

}

}
echo "<h1>".($_POST['leng'])."zzz</h1>";







echo "-----<BR><BR><BR>++++++";



}
    ?>

<?php
global $q;


//$arrStart = array(
 //array('ف', 'ڦ', 'په'),
   // array('ح', 'ه'),
    //array('د', 'ڊ','ڏ')
//);

//$arrStart= $q[$i][$x];
$arrPositions = array();
$arrResult = array();

//get a starting position set for each sub array
for ($i = 0; $i < count($q); $i++)
    $arrPositions[] = 0;

//repeat until we've run out of items in $q[0]
while (array_key_exists($arrPositions[0], $q[0])) {
    $arrTemp = array();
    $blSuccess = true;

    //go through each of the first array levels
    for ($i = 0; $i < count($q); $i++) {
        //is there a item in the position we want in the current array?
        if (array_key_exists($arrPositions[$i], $q[$i])) {
            //add that item to our temp array
            $arrTemp[] = $q[$i][$arrPositions[$i]];
        } else {
            //reset this position, and raise the one to the left
            $arrPositions[$i] = 0;
            $arrPositions[$i - 1]++;
            $blSuccess = false;
        }
    }

    //this one failed due to there not being an item where we wanted, skip to next go
    if (!$blSuccess) continue;

    //successfully adding nex line, increase the right hand count for the next one
    $arrPositions[count($q) - 1]++;

    //add our latest temp array to the result
    $arrResult[] = $arrTemp;

}



    print_r($arrResult);





    if(isset($_POST['submit'])){

for($i=0; $i<=count($arrResult)-1; $i++){

    //echo $list[$i]; 


?>

    <script>



    document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;

 </script>
 <?php  

for ($x=0; $x<= $_POST['leng']+2; $x++){






    //echo $i."-i: I : ".$x.": X <BR><BR><BR>";

    echo $arrResult[$i][$x];

}
echo "<BR><BR>";
}
echo "<h1>".($_POST['leng'])."zzz</h1>";







echo "-----<BR><BR><BR>++++++";



}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多