a.txt中有20行随机产生的数列,如下:
2928326128601232462131283250710027308938740594716691200992050511576
5352129649530193383124730478244772348721985707222557212265817305
217141333532296179938475175265792931789219830308392472584606305
2371620291160322081050531817416284225477019123161801285941026814244
283929972304551060318886921731765136928849135391662294051194618754
1809165929787147057932949630411324311737224509104016550662932273
27396236084901303873154718299242931819623155304661177528921164510335
254221462410491137971033914630292752245114969186002809930190939425
1085287492160525651862932475207612387312368408826675135332406418337
2567810118246621010283281198810903279355871571118961177731143829148
23727111515524141721964179351992331180134926914198081871053303186
378579502856625703213542353218420835730692264021219729654278515442
30215186011014395001656818458819061824708536511543271701327524725
223702764213159156022932717903282522044350522584222768193271431422354
3079720530119542370417125702274761144023302102641160114921224469221
15642298214000242538839193816839550322381321993212316517861828002
13042178002978222022331319116624809338275899045263351248023569
11252165681825711849278422768716060438517976169102391532289954712000
105084292396529699311371735329685626410510259482788519645152723476
29674179062831103792824121564178225289202161443911094228581583531951
要求通过纯批处理按照数列的大小顺序,正序输出如下:
13042178002978222022331319116624809338275899045263351248023569
217141333532296179938475175265792931789219830308392472584606305
1809165929787147057932949630411324311737224509104016550662932273
5352129649530193383124730478244772348721985707222557212265817305
15642298214000242538839193816839550322381321993212316517861828002
23727111515524141721964179351992331180134926914198081871053303186
30215186011014395001656818458819061824708536511543271701327524725
105084292396529699311371735329685626410510259482788519645152723476
254221462410491137971033914630292752245114969186002809930190939425
283929972304551060318886921731765136928849135391662294051194618754
378579502856625703213542353218420835730692264021219729654278515442
1085287492160525651862932475207612387312368408826675135332406418337
2371620291160322081050531817416284225477019123161801285941026814244
2567810118246621010283281198810903279355871571118961177731143829148
2928326128601232462131283250710027308938740594716691200992050511576
3079720530119542370417125702274761144023302102641160114921224469221
11252165681825711849278422768716060438517976169102391532289954712000
27396236084901303873154718299242931819623155304661177528921164510335
29674179062831103792824121564178225289202161443911094228581583531951
223702764213159156022932717903282522044350522584222768193271431422354
每行的数值都远远超过了cmd所能计算的最大数值。
要求,正确输出,不生成临时文件,代码高效通用。完成题目,视思路加分。
batman:
先说明下思路:
此题确实是出给我们的一大难题,为什么这要说呢?楼主要求的是文本内所有超大数值的排序,
所有的数值都远远超过了cmd所能运算的最大数值,用常规的比较法都是行不通的这是难点之一;
第二这些数值是随机生成的且字符总数不定,甚至可能达到数行和数十行之长,如采用逐字符判断
的方法来确实行最大字符数,效率将会是此类方案所无法逾越的障碍;第三楼主要求不生成临时文
件,这对用findstr /o来获取行最大字符的方案来讲,无疑是锁上了大门。
综上所述总结如下:
代码要通用就要获取行最大字符数,一种方法是逐字符法,用逐字符法效率上就存在很大问题;
第二种方法是使用findstr /o一次性获取每行字符偏移量,再通过处理获得行最大字符数,效率上比
逐字符法是高多了,但因为单用findstr /o是不能获得文本行未行字符偏移量的,必须要对未行强加
回车,在不破坏原文件的情况下就要用到临时文件。
而我们写代码时一般遵循四条原则:高效率、通用、简洁、尽量不生成临时文件,其中首要的
一条就是高效,其次是通用,至于简洁和有无临时文件都不是主要考虑因素,所以依此主次关系我
给出以下两种方案:
一、通用性差一点(数值字符都在一行内是绝对没问题的),效率高,代码简洁,无临时文件:
@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=a"
)
for /f "delims==_" %%i in ('set _') do (
set "str=%%i"
echo !str:#=!
)
pause>nul
二、通用性极高,效率一般,生成临时文件,代码较复杂:
复制代码 代码如下:
@echo off&setlocal enabledelayedexpansion
set "max=0"&set "a=0"
for /f %%i in (1.txt) do echo %%i2.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 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=%%a:!#%%i!=%%"
set ".!a!!#%%i!=a"
)
for /f "delims==." %%i in ('set .') do (
set "str=%%i"
echo !str:#=!
)
del /q 2.txt&pause>nul
pusofalse:
复制代码 代码如下:
@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!=%%a
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 _%%a (
for %%i in (!_%%a!) do set -%%i=faith
for /f "delims=-=" %%s in ('set -') do (
echo %%s
set "-%%s="
)
)
)
pause>nul
2928326128601232462131283250710027308938740594716691200992050511576
5352129649530193383124730478244772348721985707222557212265817305
217141333532296179938475175265792931789219830308392472584606305
2371620291160322081050531817416284225477019123161801285941026814244
283929972304551060318886921731765136928849135391662294051194618754
1809165929787147057932949630411324311737224509104016550662932273
27396236084901303873154718299242931819623155304661177528921164510335
254221462410491137971033914630292752245114969186002809930190939425
1085287492160525651862932475207612387312368408826675135332406418337
2567810118246621010283281198810903279355871571118961177731143829148
23727111515524141721964179351992331180134926914198081871053303186
378579502856625703213542353218420835730692264021219729654278515442
30215186011014395001656818458819061824708536511543271701327524725
223702764213159156022932717903282522044350522584222768193271431422354
3079720530119542370417125702274761144023302102641160114921224469221
15642298214000242538839193816839550322381321993212316517861828002
13042178002978222022331319116624809338275899045263351248023569
11252165681825711849278422768716060438517976169102391532289954712000
105084292396529699311371735329685626410510259482788519645152723476
29674179062831103792824121564178225289202161443911094228581583531951
要求通过纯批处理按照数列的大小顺序,正序输出如下:
13042178002978222022331319116624809338275899045263351248023569
217141333532296179938475175265792931789219830308392472584606305
1809165929787147057932949630411324311737224509104016550662932273
5352129649530193383124730478244772348721985707222557212265817305
15642298214000242538839193816839550322381321993212316517861828002
23727111515524141721964179351992331180134926914198081871053303186
30215186011014395001656818458819061824708536511543271701327524725
105084292396529699311371735329685626410510259482788519645152723476
254221462410491137971033914630292752245114969186002809930190939425
283929972304551060318886921731765136928849135391662294051194618754
378579502856625703213542353218420835730692264021219729654278515442
1085287492160525651862932475207612387312368408826675135332406418337
2371620291160322081050531817416284225477019123161801285941026814244
2567810118246621010283281198810903279355871571118961177731143829148
2928326128601232462131283250710027308938740594716691200992050511576
3079720530119542370417125702274761144023302102641160114921224469221
11252165681825711849278422768716060438517976169102391532289954712000
27396236084901303873154718299242931819623155304661177528921164510335
29674179062831103792824121564178225289202161443911094228581583531951
223702764213159156022932717903282522044350522584222768193271431422354
每行的数值都远远超过了cmd所能计算的最大数值。
要求,正确输出,不生成临时文件,代码高效通用。完成题目,视思路加分。
batman:
先说明下思路:
此题确实是出给我们的一大难题,为什么这要说呢?楼主要求的是文本内所有超大数值的排序,
所有的数值都远远超过了cmd所能运算的最大数值,用常规的比较法都是行不通的这是难点之一;
第二这些数值是随机生成的且字符总数不定,甚至可能达到数行和数十行之长,如采用逐字符判断
的方法来确实行最大字符数,效率将会是此类方案所无法逾越的障碍;第三楼主要求不生成临时文
件,这对用findstr /o来获取行最大字符的方案来讲,无疑是锁上了大门。
综上所述总结如下:
代码要通用就要获取行最大字符数,一种方法是逐字符法,用逐字符法效率上就存在很大问题;
第二种方法是使用findstr /o一次性获取每行字符偏移量,再通过处理获得行最大字符数,效率上比
逐字符法是高多了,但因为单用findstr /o是不能获得文本行未行字符偏移量的,必须要对未行强加
回车,在不破坏原文件的情况下就要用到临时文件。
而我们写代码时一般遵循四条原则:高效率、通用、简洁、尽量不生成临时文件,其中首要的
一条就是高效,其次是通用,至于简洁和有无临时文件都不是主要考虑因素,所以依此主次关系我
给出以下两种方案:
一、通用性差一点(数值字符都在一行内是绝对没问题的),效率高,代码简洁,无临时文件:
@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=a"
)
for /f "delims==_" %%i in ('set _') do (
set "str=%%i"
echo !str:#=!
)
pause>nul
二、通用性极高,效率一般,生成临时文件,代码较复杂:
复制代码 代码如下:
@echo off&setlocal enabledelayedexpansion
set "max=0"&set "a=0"
for /f %%i in (1.txt) do echo %%i2.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 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=%%a:!#%%i!=%%"
set ".!a!!#%%i!=a"
)
for /f "delims==." %%i in ('set .') do (
set "str=%%i"
echo !str:#=!
)
del /q 2.txt&pause>nul
pusofalse:
复制代码 代码如下:
@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!=%%a
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 _%%a (
for %%i in (!_%%a!) do set -%%i=faith
for /f "delims=-=" %%s in ('set -') do (
echo %%s
set "-%%s="
)
)
)
pause>nul
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月12日
2024年11月12日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]