如何找到给定字符串及其排名的排列?
例如
rank permutation
0 abc
1 acb
2 bac
3 bca
4 cab
5 cba
,如果有人要求我进行 4 级排列,答案是 cab。请给出该程序的java代码
For example,
rank permutation
0 abc
1 acb
2 bac
3 bca
4 cab
5 cba
So, if one asks give me permutation with rank 4, the answer is cab. Pls give the java code for this program
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我第一次尝试就成功了! :-)
非常好的作业,好问题,你让我很开心!这是 javascript 中的一个解决方案:
只需将其称为
permutation(5, 3, ['a', 'b', 'c'])
即可。你必须编写自己的阶乘()函数 - 作为家庭作业:-)
I made it at a first attempt!! :-)
Really good homework, nice problem, you made my day! Here is a solution in javascript:
Just call it like
permutation(5, 3, ['a', 'b', 'c'])
and that's it.You have to write your own factorial() function - as a homework :-)
这是ac#版本:基本思想是使用阶乘来确定排列,而不是通过尝试获取所有排列(您可以参考我的博客@ http://codingworkout.blogspot.com/2014/08/kth-permutation.html)
哪里
单元测试
Here is a c# version: basic idea is to using factorial to determine the permutation, rather than by trying to get all the permutations (you may refer to my blog @ http://codingworkout.blogspot.com/2014/08/kth-permutation.html)
where
Unit Test