|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『楼 主』:
出题:整理文本 (新手老鸟都来试试)
使用 LLM 解释/回答一下
要求:把 a.txt 整理成按句号换行,
即:把没有句号的行和下行拼接,把有句号的行从句号处换行
注意:有可能连续几行都没有句号,也可能一行中有多个句号。
不用考虑特殊字符问题。
当然前提是不能把a.txt所有内容都拼接为一个变量。(因为变量的字符数是有限制的)
看谁的代码最简洁、高效、加分。。!
a.txt 内容如下:
批处理文件(Batch File,简称 BAT文件)是一种在DOS
下最常用的可执行文件。它具有灵活的操纵性,可适应各
种复杂的计算机操作。所谓的批处理,就是按规定的顺序
自动执行若干个指定的DOS命令或程序。
即是把原来一个一个执行的命令汇总起来,成批的执行,而程序文件可
以移植到其它电脑中运行,因此可以大大节省命令反复输
入的繁琐。同时批处理文件还有一些编程的特点
。可以通过扩展参数来灵活的控制程序的执行,所以在日
常工作中非常实用。批处理。bat。cmd。尺有所短。寸有所长。
要求输出如下格式:
批处理文件(Batch File,简称 BAT文件)是一种在DOS 下最常用的可执行文件。
它具有灵活的操纵性,可适应各种复杂的计算机操作。
所谓的批处理,就是按规定的顺序自动执行若干个指定的DOS命令或程序。
即是把一个一个执行的命令汇总起来成批的执行,而程序文件可以移植到其它电脑中运行,因此可以大大节省命令反复输入的繁琐。
同时批处理文件还有一些编程的特点。
可以通过扩展参数来灵活的控制程序的执行,所以在日常工作中非常实用。
批处理。
bat。
cmd。
尺有所短。
寸有所长。
总结一下:
答案众多,(2楼 14楼 17楼 19楼)
2楼采取逐字读取的办法,且可以处理大多数特殊字符,但效率太低。
14楼创建一个com文件、效率高的惊人。可惜我不懂、倒是长了见识。不过此题目的还是用纯p来解决。
17楼、19楼思路一样、代码略有不同,效率也不错、基本符合楼主要求。
Last edited by 26933062 on 2008-7-13 at 10:55 PM ]
### Requirements: Organize a.txt by breaking lines at periods, that is, concatenate lines without periods with the next line, and break lines with periods at the period. Note: There may be several consecutive lines without periods, or multiple periods in one line. No need to consider special character issues. Of course, the premise is that you cannot concatenate all the content of a.txt into one variable. (Because the character limit of the variable is limited) See who has the most concise and efficient code, plus points..!
### Content of a.txt:
```
Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS. It has flexible operability and can adapt to various complex computer operations. The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order.
That is to summarize the commands executed one by one, execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. At the same time, batch processing files also have some programming characteristics. It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work. Batch processing. bat. cmd. Each has its own limitations. Each has its own advantages.
```
### Required output format:
```
Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS.
It has flexible operability and can adapt to various complex computer operations.
The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order.
That is to summarize the commands executed one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
At the same time, batch processing files also have some programming characteristics.
It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work.
Batch processing.
bat.
cmd.
Each has its own limitations.
Each has its own advantages.
```
### Summary:
There are many answers, (2nd floor 14th floor 17th floor 19th floor)
The 2nd floor adopts the method of reading character by character, and can handle most special characters, but the efficiency is too low.
The 14th floor created a com file, which is extremely efficient. Unfortunately, I don't understand it, but I have gained knowledge. However, this question is still solved with pure p.
The ideas of the 17th floor and the 19th floor are the same, the code is slightly different, and the efficiency is also good, basically meeting the requirements of the building owner.
Last edited by 26933062 on 2008-7-13 at 10:55 PM ]
|

致精致简! |
|
2008-7-13 19:51 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
 『第 2 楼』:
使用 LLM 解释/回答一下
逐字读取
@echo off
for /f "delims=" %%i in ('findstr /n .* 1.txt') do (
set "str=%%i"
setlocal enabledelayedexpansion
set str=!str:*:=!
call :lp
endlocal
)
pause&exit
:lp
if defined str (
set /p= !str:~0,1!<nul
if "!str:~0,1!"=="。" echo.
set str=!str:~1!
goto lp
)
不考虑特殊字符 也可以简化下
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do set str=%%i&call :lp
pause&exit
:lp
set /p= !str:~0,1!<nul
if "!str:~,1!"=="。" echo.
set str=!str:~1!
if defined str goto lp
Last edited by terse on 2008-7-13 at 08:23 PM ]
Read character by character
@echo off
for /f "delims=" %%i in ('findstr /n .* 1.txt') do (
set "str=%%i"
setlocal enabledelayedexpansion
set str=!str:*:=!
call :lp
endlocal
)
pause&exit
:lp
if defined str (
set /p= !str:~0,1!<nul
if "!str:~0,1!"=="。" echo.
set str=!str:~1!
goto lp
)
Ignore special characters, can also be simplified
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do set str=%%i&call :lp
pause&exit
:lp
set /p= !str:~0,1!<nul
if "!str:~,1!"=="。" echo.
set str=!str:~1!
if defined str goto lp
Last edited by terse on 2008-7-13 at 08:23 PM ]
|

简单!简单!再简单! |
|
2008-7-13 20:18 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
逐字读取不失为一个办法,但效率就大打折扣了。
加 5 分。
Reading character by character is indeed an option, but the efficiency will be greatly reduced. Add 5 points.
|

致精致简! |
|
2008-7-13 20:21 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我想法把。换成echo. 可以吗
Can I replace "." with "echo."?
|

简单!简单!再简单! |
|
2008-7-13 20:29 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 5 楼』:
要是用vbs就easy了……bat字符处理就看大家啦
使用 LLM 解释/回答一下
即是把原来一个一个执行的命令汇总起来,成批的执行,而程序文件可
以移植到其它电脑中运行,因此可以大大节省命令反复输
入的繁琐。
即是把原来一个一个执行的命令汇总起来,成批的执行,而程序文件可以移植到其它电脑中
运行,因此可以大大节省命令反复输入的繁琐。
这个的断句又是如何决定的呢?
That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
How is the punctuation of this determined?
|

S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2008-7-13 20:37 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (text.txt) do (
set str=%%i
set/p=!str!<nul>>temp.txt)
for /f "delims=。" %%i in (temp.txt) do (echo %%i。&echo.)>>result.txt
可惜事与愿违, 最后的结果只有一行,高手帮我修改下。思路我认为是对的。
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (text.txt) do (
set str=%%i
set/p=!str!<nul>>temp.txt)
for /f "delims=。" %%i in (temp.txt) do (echo %%i。&echo.)>>result.txt
It's a pity that things didn't go as expected. The final result is only one line. Experts, please help modify it. I think the idea is correct.
|

我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已. |
|
2008-7-13 20:58 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
老土兄有没有研究过文本文件一行最多容纳多少个字符?超过这个极限,你的思路还正确吗?
Has Brother Laotu ever studied the maximum number of characters that can fit in one line of a text file? If it exceeds this limit, is your idea still correct?
|

 |
|
2008-7-13 21:22 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
回 5 楼
即是把原来一个一个执行的命令汇总起来,成批的执行,而程序文件可以移植到其它电脑中运行,因此可以大大节省命令反复输入的繁琐。
这里中间没有句号,当然要算一句了。
Back to the 5th floor
That is, to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
There is no period in the middle, so of course it counts as one sentence.
|

致精致简! |
|
2008-7-13 21:44 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
这样可以吗。。。
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do set str=!str!%%a
set str=%str:。=。^&echo.^&echo.%
echo %str%
pause>nul
不好意思,忘记详细看题了。。。
Last edited by pusofalse on 2008-7-13 at 09:56 PM ]
Is this okay...
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do set str=!str!%%a
set str=%str:。=。^&echo.^&echo.%
echo %str%
pause>nul
I'm sorry, I forgot to read the question in detail...
Last edited by pusofalse on 2008-7-13 at 09:56 PM ]
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-7-13 21:52 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
那就是排版的问题?我就是不明白为什么在中字断开。。。
如果是vbs的话:replace "回车"为"空",replace "。"为 "。+回车"
Is that a typesetting issue? I just don't understand why the Chinese characters are broken...
If it's VBS: replace "carriage return" with "empty", replace "。" with "。+carriage return"
|

S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2008-7-13 21:54 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 11 楼』:
to 9楼
使用 LLM 解释/回答一下
楼主不允许这样做啊,呵呵。
The LZ doesn't allow this, heh heh.
|

 |
|
2008-7-13 21:54 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Unix下这样写应该可以成功,但Windows下就是不行,思考中。。。
sed "s/。/。\n/g" a.txt | sed "/。$/!s/\n//g"
Under Unix this should work, but under Windows it just doesn't. Thinking...
sed "s/。/。\n/g" a.txt | sed "/。$/!s/\n//g"
|

 |
|
2008-7-13 21:55 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2008-7-13 21:54:
那就是排版的问题?我就是不明白为什么在中字断开。。。
如果是vbs的话:replace "回车"为"空",replace "。"为 "。+回车"
并没有在“中”字断开,是论坛自动给它换行了。
所以我的样本中都是用空行代表换行的。这样说明白了么?
Originally posted by slore at 2008-7-13 21:54:
That's a typesetting issue? I just don't understand why it breaks at the Chinese character...
If it's VBS: replace "carriage return" with "empty", replace "。" with "。+carriage return"
It's not breaking at the "中" character, it's the forum automatically wrapping it.
So in my sample, empty lines represent line breaks. Is that clear?
|

致精致简! |
|
2008-7-13 21:59 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
|
2008-7-13 22:01 |
|
|
wxcute
中级用户
  
积分 458
发帖 211
注册 2006-7-26
状态 离线
|
『第 15 楼』:
;回10楼
使用 LLM 解释/回答一下
我觉得可能是记事本的BUG,有时用的好好的,关闭再打开时记事本就会出现中间断开的情况。
I think it might be a bug in Notepad. Sometimes it works fine, but when you close it and open it again, the Notepad will have a break in the middle.
|

┌───────┐
├→学习→实践→┤
└───────┘ |
|
2008-7-13 22:01 |
|