gpt4 book ai didi

java - 创建一个单词中一组字母的每个可能频率的列表?

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

我正在尝试编写一个算法,该算法将采用一组字母和一个包含单词大小的 int,并为此创建所有可能的字母分组,但我完全卡住了...

例子:

**Input**
Letters: E
Size: 4

**Output**
E___
E_E_
_E_E
EE__
_EE_
___E

etc..

另一个例子

**Input**
Letters: E, A
Size: 4

**Output**
EA__
AE__
E_A_
_E_A
A_E_
etc...

最佳答案

这是一个使用递归来解决问题的算法:定义一个以长度、字符数组(包括 '_' )和另一个字符串数组作为参数的方法。

String[] meth(int l;char ch[],String[] s)
Define a new String array (ns) which contains N elements where N=length of array s * l
Copy each element of s into ns thrice, each time appending an element of ch
Make a recursive call to meth with (l, ch, ns) if the length of ns is less than l


If the input is {'E', 'A'} and 4
call meth(4,new char[]{'E','A','_'},new String[]{} )

关于java - 创建一个单词中一组字母的每个可能频率的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11923484/

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