A.txt contains 20 rows of randomly generated series, as shown below:
2928326128601232462131283250710027308938740594716691200992050511576
5352129649530193383124730478244772348721985707222557212265817305
217141333532296179938475175265792931789219830308392472584606305
2371620291160322081050531817416284225477019123161801285941026814244
283929972304551060318886921731765136928849135391662294051194618754
1809165929787147057932949630411324311737224509104016550662932273
27396236084901303873154718299242931819623155304661177528921164510335
254221462410491137971033914630292752245114969186002809930190939425
1085287492160525651862932475207612387312368408826675135332406418337
2567810118246621010283281198810903279355871571118961177731143829148
23727111515524141721964179351992331180134926914198081871053303186
378579502856625703213542353218420835730692264021219729654278515442
30215186011014395001656818458819061824708536511543271701327524725
223702764213159156022932717903282522044350522584222768193271431422354
3079720530119542370417125702274761144023302102641160114921224469221
15642298214000242538839193816839550322381321993212316517861828002
13042178002978222022331319116624809338275899045263351248023569
11252165681825711849278422768716060438517976169102391532289954712000
105084292396529699311371735329685626410510259482788519645152723476
29674179062831103792824121564178225289202161443911094228581583531951
Batch Processing is required to follow the sequence of values. The output in positive order is as follows:
13042178002978222022331319116624809338275899045263351248023569
217141333532296179938475175265792931789219830308392472584606305
1809165929787147057932949630411324311737224509104016550662932273
5352129649530193383124730478244772348721985707222557212265817305
15642298214000242538839193816839550322381321993212316517861828002
23727111515524141721964179351992331180134926914198081871053303186
30215186011014395001656818458819061824708536511543271701327524725
105084292396529699311371735329685626410510259482788519645152723476
254221462410491137971033914630292752245114969186002809930190939425
283929972304551060318886921731765136928849135391662294051194618754
378579502856625703213542353218420835730692264021219729654278515442
1085287492160525651862932475207612387312368408826675135332406418337
2371620291160322081050531817416284225477019123161801285941026814244
2567810118246621010283281198810903279355871571118961177731143829148
2928326128601232462131283250710027308938740594716691200992050511576
3079720530119542370417125702274761144023302102641160114921224469221
11252165681825711849278422768716060438517976169102391532289954712000
27396236084901303873154718299242931819623155304661177528921164510335
29674179062831103792824121564178225289202161443911094228581583531951
223702764213159156022932717903282522044350522584222768193271431422354
The values in each row far exceed the maximum value that can be calculated by cmd.
Required, correct output, no temporary files are generated, and the code is efficient and common. Complete the question and add points based on your ideas.
Batman:
First, describe the following ideas:
This question is indeed a major challenge for us. Why? The main requirement is to sort all the large numbers in the text,
All values far exceed the maximum value that can be calculated by cmd. It is not feasible to use the conventional comparative method. This is one of the difficulties;
Second, these values are randomly generated and the total number of characters is not fixed, and may even exceed the length of several and dozens of lines. For example, the values are determined by character.
To ensure the maximum number of characters in the line, efficiency will be insurmountable obstacles to such a solution; the third main requirement is not to generate temporary text
To use findstr/o to obtain the maximum number of characters in a row.
The summary is as follows:
To use common code, you must obtain the maximum number of characters in a row. One method is to use the character-by-character method, which poses a big problem in efficiency;
The second method is to use findstr/o to get the character offset of each line at a time, and then obtain the maximum number of characters in the line through processing, which is more efficient
The character-by-character method is much higher, but because findstr/o alone cannot get the offset of unlineed characters in text lines, it must be imposed on unlineed lines.
Press enter to use a temporary file without damaging the original file.
When writing code, we generally follow four principles: high efficiency, general purpose, concise, and do not generate temporary files as much as possible.
One is efficiency, followed by general purpose. Simplicity and the absence of temporary files are not the main considerations.
The following two solutions are provided:
I. The versatility is almost the same (the numeric characters are in one line is absolutely no problem), high efficiency, concise code, no temporary files:
@ Echo off & setlocal enabledelayedexpansion
For/l % I in (1, 1, 80) do set "kong =! Kong! #"
For/f % I in (1.txt) do (
Set "str = % I % kong %"
Set "a =! Str :~, 80! "
Set "a =! A: % I =! "
Set "_! A! % I ="
)
For/f "delims = _" % I in ('set _ ') do (
Set "str = % I"
Echo! Str: # =!
)
Pause> nul
2. Extremely high versatility and efficiency. Temporary files are generated, and the code is complicated:
Copy codeThe Code is as follows: @ echo off & setlocal enabledelayedexpansion
Set "max = 0" & set "a = 0"
For/f % I in (1.txt) do echo % I> 2.txt
Echo.> 2.txt
For/f "tokens = 1, 2 * delims =:" % I in ('findstr/n/o. * 2.txt ') do (
Set/a n + = 1, m = n-1
Set "num = % I" & set "_! N! = % J "& set" # % I = % k"
If! M! Gtr 0 set/a = _! N! -_! M! -2
If! Max! Lss! A! Set "max =! A! "
)
Set/a num-= 1
For/l % I in (1,1, % max %) do set "kong =! Kong! #"
For/l % I in (1, 1, % num %) do (
Set "str =! # % I! % Kong %"
Set "a =! Str :~, % Max %! "
Call, set "a = % :! # % I! = %"
Set ".! A !! # % I! ="
)
For/f "delims =." % I in ('set. ') do (
Set "str = % I"
Echo! Str: # =!
)
Del/q 2.txt& pause> nul
Pusofalse:Copy codeThe Code is as follows: @ echo off & setlocal enabledelayedexpansion
Set m = 0
For/f "tokens = 1, * delims =:" % a in ('findstr/o. * 1.txt ') do (
Set/a n + = 1, l = n-1, y + = 1
Set ..! N! = %
Set ##! Y! = % B
If! N! Geq 2 (
Call, set/a s = % ..! N! %-% ..! L! %-2, line + = 1
Call, set "_! S! = % _! S! % ##! Line! %"
If! S! Geq! M! Set m =! S!
)
)
For/f "skip = 1 delims =:" % a in ('^ (echo! # % Y %! ^ & Echo. ^) ^ | findstr/o. * ') do set/a final =%% A-3
Call, set "_ % final % = % _! Final! %! # % Y %! "
If % final % geq! M! Set m = % final %
For/l % a in (1 1% m %) do (
If defined _ % (
For % I in (! _ % !) Do set-% I = faith
For/f "delims =-=" % s in ('set-') do (
Echo % s
Set "-% s ="
)
)
)
Pause> nul