You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求数字字符串的所有两两配对或单独拆分的可能组合

需求说明

给定数字字符串(例如"123456"),需要找出其所有可两两配对或单独拆分的组合,示例包括:

  • 12 3 4 5 6
  • 12 34 5 6
  • 1 23 4 56
已尝试的代码

本人编写了以下Python代码,但未能完全实现上述需求:

strr = list("123456")
x = list("123456")

for i in range(int(len(strr)/2)):
    newlist = []
    for j in range(i):
        newlist.append(x[j])
    newlist.append(x[i] + x[i+1])
    for j in range(len(x))[i+2:]:
        newlist.append(x[j])
    x = newlist.copy()
    b = x.copy()
    for f in range(len(b))[i:]:
        if f == i:
            print(b)
            continue
        b[f] = b[f - 1][1] + b[f]
        b[f - 1] = b[f - 1][0]
        print(b)
当前代码输出

上述代码的输出如下:
代码输出结果

内容的提问来源于stack exchange,提问作者Rasmus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 08:01:33