| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 977 人关注过本帖
标题:如下这个排序程序如何做?
只看楼主 加入收藏
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
如下这个排序程序如何做?
如下俩数列s10和s11,各任意取一个与另一个数列的数相加,和再排序,如何做呢?
s10=
/1/4/9/16/25/1/8/27/64/125/1/32/243/1024/3125/1/128/2187/16384/78125

s11=
/2/5/8/9/10/12/13/16/17/18/20/24/25/26/28/29/31/32/33/34/
35/36/40/41/43/48/50/52/54/57/59/64/65/68/72/73/80/89/91/96/
126/128/129/132/133/134/136/137/141/144/150/152/153/155/157/160/189/192/244/247/
250/251/252/253/256/259/268/270/275/307/368/371/486/1025/1028/1032/1033/1040/1049/1051/
1056/1088/1149/1152/1267/2048/2188/2191/2195/2196/2203/2212/2214/2219/2251/2312/2315/2430/3126/3129/
3133/3134/3141/3150/3152/3157/3189/3211/3250/3253/3368/4149/4374/5312/6250/16385/16388/16392/16393/16400/
16409/16411/16416/16448/16509/16512/16627/17408/18571/19509/32768/78126/78129/78133/78134/78141/78150/78152/78157/78189/
78250/78253/78368/79149/80312/81250/94509/156250
搜索更多相关主题的帖子: 相加 排序 一个数 任意 数列 
2023-01-08 23:22
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
收藏
得分:0 
如下是可调用程序:(不知道对不对)
Private Function paixu0(a As String, b As String) As String
Dim i As Integer
Dim ak(), s105, cr(), f, bk()
s103 = a
Set f = CreateObject("Scripting.Dictionary")
s105 = Split(s103, "/")
s205 = Split(b, "/")
   j1 = UBound(s105)
   j2 = UBound(s105)
   Print j1
   For k = 1 To j1
      n1 = n1 + 1
       ReDim Preserve ak(1 To n1)
      ak(n1) = s105(n1)
    Next
    For k = 1 To j2
      n2 = n2 + 1
        ReDim Preserve bk(1 To n2)
       bk(n2) = s205(n2)
    Next
    Print ak(1)
     n = 0
        For k = 1 To j1
           For i = 1 To j2
             n = n + 1
             ReDim Preserve cr(1 To n)
            m = Val(ak(k)) + Val(bk(i))
            f(m) = ""
      Next
    Next
      n = 0
      m = f.Keys
      For i = 0 To f.Count - 1
          ReDim Preserve cr(1 To i + 1)
          cr(i + 1) = m(i)
      Next
     For i = 1 To UBound(cr) - 1
        For j = i + 1 To UBound(cr)
            If cr(i) > cr(j) Then
                temp = cr(j)
                cr(j) = cr(i)
                cr(i) = temp  'c数组是排序好的
            End If
        Next j
        
       ' If i Mod 20 = 0 Then
       ' s104 = s104 & temp & "/" & vbCrLf
       ' Else
       ' s104 = s104 & temp & "/"
       ' End If
    Next i
   
      For i = 1 To UBound(cr)
        If i Mod 20 = 0 Then
          s104 = s104 & cr(i) & "/" & vbCrLf
        Else
          s104 = s104 & cr(i) & "/"
        End If
     Next
         Print temp
         MsgBox "ok"
     MsgBox s104  '显示数组
     paixu0 = s104
End Function
2023-01-08 23:57
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
收藏
得分:0 
如下为结果:
输入:1~5输出:
/3/6/9/10/11/12/13/14/16/17/18/19/20/21/22/24/25/26/27/28/
29/30/32/33/34/35/36/37/38/39/40/41/42/43/44/45/47/48/49/50/
51/52/53/54/55/56/57/58/59/60/61/63/64/65/66/69/72/73/74/76/
77/80/81/82/84/88/89/90/92/93/95/96/97/98/127/130/133/134/135/136/
137/138/140/141/142/143/144/145/146/148/149/150/151/152/153/154/156/157/158/159/
160/161/162/245/248/251/252/253/255/256/259/260/261/263/267/268/269/271/272/274/
275/276/277/1026/1029/1032/1033/1034/1036/1037/1040/1041/1042/1044/1048/1049/1050/1052/1053/1055/
1056/1057/1058/2189/2192/2195/2196/2197/2199/2200/2203/2204/2205/2207/2211/2212/2213/2215/2216/2218/
2219/2220/2221/3127/3130/3133/3134/3135/3137/3138/3141/3142/3143/3145/3149/3150/3151/3153/3154/3156/
3157/3158/3159/16386/16389/16392/16393/16394/16396/16397/16400/16401/16402/16404/16408/16409/16410/16412/16413/16415/
16416/16417/16418/78127/78130/78133/78134/78135/78137/78138/78141/78142/78143/78145/78149/78150/78151/78153/78154/78156/
78157/78158/78159/

[此贴子已经被作者于2023-1-10 09:27编辑过]

2023-01-08 23:58
独木星空
Rank: 8Rank: 8
来 自:河北省曲阳县
等 级:贵宾
威 望:48
帖 子:681
专家分:543
注 册:2016-6-29
收藏
得分:5 
两层嵌套循环,最后安升序排序即可获得结果。用vfp很容易实现,排序仅一个语句就能完成。

素数问题的解决是我学习编程永恒的动力。
2023-01-09 14:43
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
收藏
得分:0 
回复 4楼 独木星空
啊,好!不会那个,这个程序关键是太占用内存,数列长了就溢出,如何改进一下,如何就少占用内存了?
2023-01-09 19:01
独木星空
Rank: 8Rank: 8
来 自:河北省曲阳县
等 级:贵宾
威 望:48
帖 子:681
专家分:543
注 册:2016-6-29
收藏
得分:5 
回复 5楼 ysr2857
用数组可以解决问题,这点数据不至于数据溢出。

素数问题的解决是我学习编程永恒的动力。
2023-01-09 22:28
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:7
帖 子:95
专家分:341
注 册:2022-11-3
收藏
得分:2 
程序代码:
Sub test()
Dim s1() As String, s2() As String, s3() As Long, i&, j&, k&
s10 = "/1/4/9/16/25/1/8/27/64/125/1/32/243/1024/3125/1/128/2187/16384/78125"
s11 = "/2/5/8/9/10/12/13/16/17/18/20/24/25/26/28/29/31/32/33/34/35/36/40/41/43/48/50/52/54/57/59/64/65/68/72/73/80/89/91/96/126/128/129/132/133/134/136/137/141/144/150/152/153/155/157/160/189/192/244/247/250/251/252/253/256/259/268/270/275/307/368/371/486/1025/1028/1032/1033/1040/1049/1051/1056/1088/1149/1152/1267/2048/2188/2191/2195/2196/2203/2212/2214/2219/2251/2312/2315/2430/3126/3129/3133/3134/3141/3150/3152/3157/3189/3211/3250/3253/3368/4149/4374/5312/6250/16385/16388/16392/16393/16400/16409/16411/16416/16448/16509/16512/16627/17408/18571/19509/32768/78126/78129/78133/78134/78141/78150/78152/78157/78189/78250/78253/78368/79149/80312/81250/94509/156250"
s1 = Split(s10, "/")
s2 = Split(s11, "/")
ReDim s3(1 To Val(s1(UBound(s1))) + Val(s2(UBound(s2))))
For i = 1 To UBound(s1)
For j = 1 To UBound(s2)
s3(Val(s1(i)) + Val(s2(j))) = 1
Next j, i
ReDim s1(UBound(s3))
For i = 1 To UBound(s3)
If s3(i) Then s1(k) = i: k = k + 1
Next
ReDim Preserve s1(k - 1)
Debug.Print Join(s1, "/")
End Sub
2023-01-09 23:38
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
收藏
得分:0 
回复 7楼 mrexcel
学习了,谢谢老师!如下位程序结果:
3/6/9/10/11/12/13/14/16/17/18/19/20/21/22/24/25/26/27/28/29/30/32/33/34/35/36/37/38/39/40/41/42/43/44/45/47/48/49/50/51/52/53/54/55/56/57/58/59/60/61/62/63/64/65/66/67/68/69/70/72/73/74/75/76/77/79/80/81/82/84/86/88/89/90/91/92/93/95/96/97/98/99/100/104/105/107/112/114/116/118/121/123/127/128/129/130/132/133/134/135/136/137/138/140/141/142/143/144/145/146/148/149/150/151/152/153/154/155/156/157/158/159/160/161/162/163/164/165/166/168/169/171/173/175/176/177/178/179/180/182/184/185/187/189/190/192/193/196/197/198/200/201/205/208/214/216/217/219/221/224/245/248/251/252/253/254/255/256/257/258/259/260/261/262/263/264/265/266/267/268/269/271/272/274/275/276/277/278/279/280/281/282/283/284/285/286/288/291/293/295/297/300/302/307/308/311/314/315/316/317/320/323/332/334/339/369/371/372/375/376/377/378/379/380/381/384/387/393/395/396/398/400/403/432/435/487/490/493/494/495/496/499/502/511/513/518/550/611/614/729/1026/1029/1032/1033/1034/1036/1037/1040/1041/1042/1044/1048/1049/1050/1052/1053/1055/1056/1057/1058/1059/1060/1064/1065/1067/1072/1074/1076/1078/1081/1083/1088/1089/1092/1096/1097/1104/1113/1115/1120/1150/1152/1153/1156/1157/1158/1160/1161/1165/1168/1174/1176/1177/1179/1181/1184/1213/1216/1268/1271/1274/1275/1276/1277/1280/1283/1292/1294/1299/1331/1392/1395/1510/2049/2052/2056/2057/2064/2073/2075/2080/2112/2173/2176/2189/2192/2195/2196/2197/2199/2200/2203/2204/2205/2207/2211/2212/2213/2215/2216/2218/2219/2220/2221/2222/2223/2227/2228/2230/2235/2237/2239/2241/2244/2246/2251/2252/2255/2259/2260/2267/2276/2278/2283/2291/2313/2315/2316/2319/2320/2321/2323/2324/2328/2331/2337/2339/2340/2342/2344/2347/2376/2379/2431/2434/2437/2438/2439/2440/2443/2446/2455/2457/2462/2494/2555/2558/2673/3072/3127/3130/3133/3134/3135/3137/3138/3141/3142/3143/3145/3149/3150/3151/3153/3154/3156/3157/3158/3159/3160/3161/3165/3166/3168/3173/3175/3177/3179/3182/3184/3189/3190/3193/3197/3198/3205/3212/3214/3215/3216/3219/3220/3221/3227/3236/3238/3243/3251/3253/3254/3257/3258/3259/3261/3262/3266/3269/3275/3277/3278/3280/3282/3285/3314/3317/3336/3339/3369/3372/3375/3376/3377/3378/3381/3384/3393/3395/3400/3432/3454/3493/3496/3611/4150/4153/4157/4158/4165/4174/4176/4181/4213/4235/4274/4277/4375/4378/4382/4383/4390/4392/4399/4401/4406/4438/4499/4502/4617/5173/5313/5316/5320/5321/5328/5337/5339/5344/5376/5398/5437/5440/5555/6251/6254/6258/6259/6266/6275/6277/6282/6314/6336/6375/6378/6493/6561/7274/7499/8437/9375/16386/16389/16392/16393/16394/16396/16397/16400/16401/16402/16404/16408/16409/16410/16412/16413/16415/16416/16417/16418/16419/16420/16424/16425/16427/16432/16434/16436/16438/16441/16443/16448/16449/16452/16456/16457/16464/16473/16475/16480/16510/16512/16513/16516/16517/16518/16520/16521/16525/16528/16534/16536/16537/16539/16541/16544/16573/16576/16628/16631/16634/16635/16636/16637/16640/16643/16652/16654/16659/16691/16752/16755/16870/17409/17412/17416/17417/17424/17433/17435/17440/17472/17533/17536/17651/18432/18572/18575/18579/18580/18587/18596/18598/18603/18635/18696/18699/18814/19510/19513/19517/19518/19525/19534/19536/19541/19573/19595/19634/19637/19752/20533/20758/21696/22634/32769/32772/32776/32777/32784/32793/32795/32800/32832/32893/32896/33011/33792/34955/35893/49152/78127/78130/78133/78134/78135/78137/78138/78141/78142/78143/78145/78149/78150/78151/78153/78154/78156/78157/78158/78159/78160/78161/78165/78166/78168/78173/78175/78177/78179/78182/78184/78189/78190/78193/78197/78198/78205/78214/78216/78221/78251/78253/78254/78257/78258/78259/78261/78262/78266/78269/78275/78277/78278/78280/78282/78285/78314/78317/78369/78372/78375/78376/78377/78378/78381/78384/78393/78395/78400/78432/78493/78496/78611/79150/79153/79157/79158/79165/79174/79176/79181/79213/79274/79277/79392/80173/80313/80316/80320/80321/80328/80337/80339/80344/80376/80437/80440/80555/81251/81254/81258/81259/81266/81275/81277/81282/81314/81336/81375/81378/81493/82274/82499/83437/84375/94510/94513/94517/94518/94525/94534/94536/94541/94573/94634/94637/94752/95533/96696/97634/110893/156251/156254/156258/156259/156266/156275/156277/156282/156314/156375/156378/156493/157274/158437/159375/172634/234375
2023-01-10 07:14
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:706
专家分:54
注 册:2020-2-10
收藏
得分:0 
数列载长一点儿,如下这一步就会内存溢出的:
ReDim s3(1 To Val(s1(UBound(s1))) + Val(s2(UBound(s2))))

咋回事?
2023-01-10 12:03
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:7
帖 子:95
专家分:341
注 册:2022-11-3
收藏
得分:3 
以下是引用ysr2857在2023-1-10 12:03:15的发言:

数列载长一点儿,如下这一步就会内存溢出的:
ReDim s3(1 To Val(s1(UBound(s1))) + Val(s2(UBound(s2))))

咋回事?

这个代码是一个取巧,对于规模较大的数据,还是直接写一段排序代码,冒泡,插入,选择,归并,快速,希尔均可。
建议学习python吧

程序代码:
s10 = '/1/4/9/16/25/1/8/27/64/125/1/32/243/1024/3125/1/128/2187/16384/78125'
s11 = '/2/5/8/9/10/12/13/16/17/18/20/24/25/26/28/29/31/32/33/34/35/36/40/41/43/48/50/52/54/57/59/64/65/68/72/73/80/89/91/96/126/128/129/132/133/134/136/137/141/144/150/152/153/155/157/160/189/192/244/247/250/251/252/253/256/259/268/270/275/307/368/371/486/1025/1028/1032/1033/1040/1049/1051/1056/1088/1149/1152/1267/2048/2188/2191/2195/2196/2203/2212/2214/2219/2251/2312/2315/2430/3126/3129/3133/3134/3141/3150/3152/3157/3189/3211/3250/3253/3368/4149/4374/5312/6250/16385/16388/16392/16393/16400/16409/16411/16416/16448/16509/16512/16627/17408/18571/19509/32768/78126/78129/78133/78134/78141/78150/78152/78157/78189/78250/78253/78368/79149/80312/81250/94509/156250'
s1 = s10.split('/')
s2 = s11.split('/')
s=[]
for a in s1[1:]:
    for b in s2[1:]:
        c=int(a)+int(b)
        if not c in s:
            s.append(c)
s.sort()
print(s)
2023-01-10 16:55
快速回复:如下这个排序程序如何做?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032641 second(s), 8 queries.
Copyright©2004-2023, BCCN.NET, All Rights Reserved