In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use batch processing to solve numerical sorting problems. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
There are 20 randomly generated sequences in a.txt, as follows:
2928326128601232462131283250710027308938740594716691200992050511576
5352129649530193383124730478244772348721985707222557212265817305
217141333532296179938475175265792931789219830308392472584606305
2371620291160322081050531817416284225477019123161801285941026814244
283929972304551060318886921731765136928849135391662294051194618754
1809165929787147057932949630411324311737224509104016550662932273
27396236084901303873154718299242931819623155304661177528921164510335
254221462410491137971033914630292752245114969186002809930190939425
1085287492160525651862932475207612387312368408826675135332406418337
2567810118246621010283281198810903279355871571118961177731143829148
23727111515524141721964179351992331180134926914198081871053303186
378579502856625703213542353218420835730692264021219729654278515442
30215186011014395001656818458819061824708536511543271701327524725
223702764213159156022932717903282522044350522584222768193271431422354
3079720530119542370417125702274761144023302102641160114921224469221
15642298214000242538839193816839550322381321993212316517861828002
13042178002978222022331319116624809338275899045263351248023569
11252165681825711849278422768716060438517976169102391532289954712000
105084292396529699311371735329685626410510259482788519645152723476
29674179062831103792824121564178225289202161443911094228581583531951
It is required to use pure batch processing in the order of the size of the sequence, and the positive order output is as follows:
13042178002978222022331319116624809338275899045263351248023569
217141333532296179938475175265792931789219830308392472584606305
1809165929787147057932949630411324311737224509104016550662932273
5352129649530193383124730478244772348721985707222557212265817305
15642298214000242538839193816839550322381321993212316517861828002
23727111515524141721964179351992331180134926914198081871053303186
30215186011014395001656818458819061824708536511543271701327524725
105084292396529699311371735329685626410510259482788519645152723476
254221462410491137971033914630292752245114969186002809930190939425
283929972304551060318886921731765136928849135391662294051194618754
378579502856625703213542353218420835730692264021219729654278515442
1085287492160525651862932475207612387312368408826675135332406418337
2371620291160322081050531817416284225477019123161801285941026814244
2567810118246621010283281198810903279355871571118961177731143829148
2928326128601232462131283250710027308938740594716691200992050511576
3079720530119542370417125702274761144023302102641160114921224469221
11252165681825711849278422768716060438517976169102391532289954712000
27396236084901303873154718299242931819623155304661177528921164510335
29674179062831103792824121564178225289202161443911094228581583531951
223702764213159156022932717903282522044350522584222768193271431422354
The value of each row far exceeds the maximum value that cmd can calculate.
Requirements, correct output, do not generate temporary files, the code is efficient and universal. To complete the topic, add points according to the train of thought.
Batman:
Let's start with the following ideas:
This question is indeed a big problem for us, why do we have to say it? What the landlord requires is the sorting of all the super-large values in the text.
All the values far exceed the maximum value that cmd can operate, and it is impossible to use the conventional comparison method, which is one of the difficulties.
Second, these values are randomly generated and the total number of characters is uncertain, and may even reach the length of several lines and dozens of lines, such as character-by-character judgment
In order to implement the maximum number of characters, efficiency will be an insurmountable obstacle for such schemes; the third floor requires that no temporary text be generated.
Element, which undoubtedly locks the door for the solution of using findstr / o to get the largest character of a line.
To sum up, the summary is as follows:
If the code is to be universal, it is necessary to obtain the maximum number of characters on a line. One way is to use the character-by-character method, which has a big problem in efficiency.
The second method is to use findstr / o to obtain the character offset per line at one time, and then to obtain the maximum number of characters per line through processing, which is more efficient than
Character-by-character method is much higher, but because findstr / o alone cannot obtain the unline character offset of a line of text, it must be imposed on the unline
Enter, the temporary file will be used without destroying the original file.
When we write code, we generally follow four principles: efficient, universal, concise, and try not to generate temporary files, the most important of which is
One is efficient, the second is general, as for simplicity and the presence or absence of temporary documents are not the main considerations, so according to this primary and secondary relationship
The following two schemes are given:
First, poor versatility (it is absolutely no problem that numeric characters are all in one line), high efficiency, concise code, no temporary files:
@ echo off&setlocal enabledelayedexpansion
For / l% I in (1meme 1mem80) do set "Kongqiaokongjia #"
For / f% I in (1.txt) do (
Set "str=%%i%kong%"
Set "axioms, struts, etc."
Set "axialug%% iTunes!"
Set "_! aura%% iTuna"
)
For / f "delims==_"% I in ('set _') do (
Set "str=%%i"
Echo! struts!
)
Pause > nul
Second, the versatility is very high, the efficiency is general, the temporary file is generated, and the code is complicated:
The code is as follows:
@ echo off&setlocal enabledelayedexpansion
Set "max=0" & set "axiom 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 naughty horse 1
Set "num=%%i" & set "_! nasty% j" & set "#% iTunes% k"
If! m! Gtr 0 set / a horse color / a horse color color 2
If! max! Lss! a! Set "maxmaxroomrooma!"
)
Set / a num-=1
For / l%% I in (1JI% max%) do set "kongqiaokongfang #"
For / l%% I in (1JI% num%) do (
Set "stranded cargo%% iTunes% Kong%"
Set "axioms strughuanghuanjia"% max%! "
Call,set "aura%% aRom customers%% iTunes%%"
Set ".! axioms%% iTunes a"
)
For / f "delims==."% I in ('set.') Do (
Set "str=%%i"
Echo! struts!
)
Del / Q 2.txt&pause > nul
Pusofalse:
The code is as follows:
@ echo off&setlocal enabledelayedexpansion
Set massif 0
For / f "tokens=1,* delims=:"% an in ('findstr/o. * 1.txt') do (
Set/a naughty 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
Set..! nasty% a
Set # #! yawning% b
If! n! Geq 2 (
Call,set/a slots%.. salary% copyright% copyright%%.. Little% Mutual% Equi% 2thi lineages 1
Call,set "_! slots%% percent"
If! s! Geq! m! Set masks!
)
)
For / f "skip=1 delims=:"% an in ('^ (echo! # #% y%! ^ & echo.^) ^ | findstr/o. *') do set/a final=%%a-3
Call,set "_% finals% percent! # #% y%!"
If final% geq! M! Set masked% final%
For / l an in (11 m) do (
If defined _% a (
For I in (! _% a!) Do set -% i=faith
For / f "delims=-="% s in ('set -') do (
Echo s
Set "-% s ="
)
)
)
Pause > nul
This is the end of this article on "how to use batch processing to solve numerical sorting problems". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.