就是怎么去吧11239这五位数字的排列组合一一的显示出来

因为鄙人不是很懂,不怎么会懂这些,所以向各位请教,希望能帮帮我,(可以有偿)。五位数字11239,怎么看到这五位数字的全部排列组合。谢谢!

这个可以使用回溯算法计算全排列
因为我是写js的 这里简单贴下js的代码

var permute = function(nums) {
    const res = [], path = [];
    backtracking(nums, nums.length, []);
    return res;
    
    function backtracking(n, k, used) {
        if(path.length === k) {
            res.push(Array.from(path));
            return;
        }
        for (let i = 0; i < k; i++ ) {
            if(used[i]) continue;
            path.push(n[i]);
            used[i] = true; // 同支
            backtracking(n, k, used);
            path.pop();
            used[i] = false;
        }
    }
};

为了方便,我也帮你计算出了结果

11239
11293
11329
11392
11923
11932
12139
12193
12319
12391
12913
12931
13129
13192
13219
13291
13912
13921
19123
19132
19213
19231
19312
19321
11239
11293
11329
11392
11923
11932
12139
12193
12319
12391
12913
12931
13129
13192
13219
13291
13912
13921
19123
19132
19213
19231
19312
19321
21139
21193
21319
21391
21913
21931
21139
21193
21319
21391
21913
21931
23119
23191
23119
23191
23911
23911
29113
29131
29113
29131
29311
29311
31129
31192
31219
31291
31912
31921
31129
31192
31219
31291
31912
31921
32119
32191
32119
32191
32911
32911
39112
39121
39112
39121
39211
39211
91123
91132
91213
91231
91312
91321
91123
91132
91213
91231
91312
91321
92113
92131
92113
92131
92311
92311
93112
93121
93112
93121
93211
93211

如有帮助请采纳回答,谢谢


s = set()
def print_pc(nums, pc):
    if len(nums) == 0:
        # 如果不需要去重,直接print
        # print(pc)
        s.add(int(pc))
    else:
        for num in nums:
            tmp = nums.copy()
            tmp.remove(num)
            print_pc(tmp, num + pc)
        

num = '11239'
nums = list(num)
print_pc(nums, '')

print(s)

11392, 12931, 13192, 19213, 32911, 21391, 11923, 21139, 92311, 23191, 21913, 31129, 93211, 11932, 11293, 19231, 12319, 12193, 13219, 31912, 39211, 21931, 91312, 31921, 19123, 93112, 91321, 29113, 31291, 19132, 32191, 93121, 11329, 21319, 39112, 21193, 13129, 29131, 91213, 23119, 39121, 92113, 13912, 31192, 91231, 13921, 92131, 23911, 12391, 11239, 13291, 12139, 19312, 12913, 91123, 31219, 32119, 19321, 91132, 29311

有没有要求用什么语言代码实现?
另外,第一个1和第二个1交换顺序是算一种新的排列还是不算一种新的排列?然后,这些数字是否允许重复出现?
下面这个是用oracle的sql实现的

with t as (
select 1 rn, 1 a from dual union all
select 2, 1 from dual union all
select 3, 2 from dual union all
select 4, 3 from dual union all
select 5, 9 from dual )
select distinct t1.a||t2.a||t3.a||t4.a||t5.a 
from t t1,t t2,t t3,t t4,t t5
where t1.rn<>t2.rn and t1.rn<>t3.rn and t1.rn<>t4.rn and t1.rn<>t5.rn 
and t2.rn<>t3.rn and t2.rn<>t4.rn and t2.rn<>t5.rn 
and t3.rn<>t4.rn and t3.rn<>t5.rn 
and t4.rn<>t5.rn 

img

结果不重复的有60个,如果那两个1要当成不一样的,把distinct去掉,就是120个