中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-10 12:51
47,815 topics / 349,930 posts / today 0 new / 48,291 members
DOS批处理 & 脚本技术(批处理室) » [Help] Numerical Sorting (Difficulty: Difficult, Problem Solved)
Printable Version  14,711 / 31
Floor16 26933062 Posted 2008-04-30 08:37
银牌会员 Posts 879 Credits 2,268
Hehe, didn't expect that number sorting actually caused the second storm in the union. It's lively.

Also post a piece of previous code to add some fun
:
Floor17 zh159 Posted 2008-04-30 10:13
金牌会员 Posts 1,467 Credits 3,687
It can range from negative numbers to positive numbers, and it will remove duplicate numbers. It cannot correctly handle numbers that start with 0.
Floor18 qzwqzw Posted 2008-04-30 16:01
银牌会员 Posts 636 Credits 2,343
Simplify the terse scheme, and we can modify it if there are deficiencies.

Floor19 lxmxn Posted 2008-04-30 17:25
版主 Posts 4,938 Credits 11,386
So lively, I'll also add a part. The drawback is that the efficiency is a bit low...



In the for, 5 is specified according to the maximum number of digits. If you don't know, you can also write a for statement to calculate it. I omitted it here.
Floor20 huahua0919 Posted 2008-04-30 18:02
银牌会员 Posts 780 Credits 1,608
Originally posted by lxmxn at 2008-4-30 05:25 PM:
So lively, I'll also add one, the shortcoming is that the efficiency is a bit low...
Floor21 lxmxn Posted 2008-04-30 23:14
版主 Posts 4,938 Credits 11,386
Originally posted by huahua0919 at 2008-4-30 18:02:

I didn't understand the moderator's code. Can you explain it?
It seems that negative numbers are not supported for sorting

It's simply to find numbers from 1-digit to 5-digit using findstr according to the number of digits, and then sort them with sort. But the premise is that the numbers are all positive integers and the maximum number of digits is known. Strictly speaking, this is not sorting~
Floor22 MLQX Posted 2008-05-02 05:09
初级用户 Posts 15 Credits 28
Why add a long string of zeros in front of a number, and then when traversing in the environment variable, the zeros are truncated, and they can be automatically sorted? Please give your advice, great experts.
Floor23 MLQX Posted 2008-05-02 11:26
初级用户 Posts 15 Credits 28
Why is nobody replying to me?
Floor24 slore Posted 2008-05-02 12:14
铂金会员 Posts 2,478 Credits 5,212
99
1
888

The sorting result is
1
888
99

If padding with zeros, the result is:

00001
00099
00888

……
Floor25 MLQX Posted 2008-05-02 12:23
初级用户 Posts 15 Credits 28
Originally posted by MLQX at 2008-5-2 11:26 AM:
Thanks.
[ Last edited by MLQX on 2008-5-2 at 12:34 PM ]
Floor26 MLQX Posted 2008-05-02 12:45
初级用户 Posts 15 Credits 28
Originally posted by zh159 at 2008-4-30 01:51 AM:
Used before, forgot where it came from
Floor27 MLQX Posted 2008-05-02 12:53
初级用户 Posts 15 Credits 28
Originally posted by plp626 at 2008-4-29 11:59 PM:


Is it an implicit end-of-file mark in a text file? Or is it a mark indicating the beginning or end of a line?

[ Last edited by MLQX on 2008-5-2 at 01:24 PM ]
Floor28 bat-zw Posted 2008-05-03 22:19
金牌会员 Posts 1,276 Credits 3,105
&&Unexpectedly, a single stone stirs up thousands of waves. I haven't been to the forum for a few days, and this post has become an essence post and is so popular, which is really beyond my initial expectation. Today, I studied my original code again and have the following highly universal code:
Floor29 MLQX Posted 2008-05-04 00:41
初级用户 Posts 15 Credits 28
@echo off&for /f "delims=" %%i in ('sort /+n c.txt') do echo %%i

If comparing three-digit numbers, change the n value to 3.
Floor30 terse Posted 2008-05-04 12:02
银牌会员 Posts 946 Credits 2,404
Originally posted by zw19750516 at 2008-5-3 22:19:
&&Unexpectedly, a single stone stirs up a thousand waves. I haven't been to the forum for a few days, and this post has become an essence post, and it's so popular. It's really beyond my original expectation. Today, I studied my original code again and have the following...

Not universal. You try set "str=1111 111 20 14 13 19 18 16 11 5 -7"
Prev  1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023