gpt4 book ai didi

php - 在具有所有可能性的字符之间生成点

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:55:59 25 4
gpt4 key购买 nike

我正在寻找一种 PHP 算法来输出所有带点的可能性。产生我们可以把 do 放在单词的任何地方,但现在允许彼此重复两个点。例如“注释”输出如下:

note
n.ote
n.o.te
n.o.t.e
no.t.e
not.e
n.ot.e
....

下面的输出也是错误的:

n..ote (repeat dots right after each other)
.note (put dots at first of word)
note. (put dots at end of word)

最佳答案

递归方式:

Put current char of source in the result string
if current char is the last one
output result
else
call recursive function with the next char index
add dot to result and call recursive function with the next char index

迭代方式:

2^(Len-1) 与点的组合,其中 Len 为字长。为 k = 0..2^(Len-1) - 1 创建一个循环,并在这些地方为每个 k 插入点,其中 k 的二进制表示包含 1 (k=2 = 二进制 010 = > po.le)

关于php - 在具有所有可能性的字符之间生成点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36838550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com