|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by HAT at 2008-9-20 05:30 AM:
那就用2楼的思路吧
@echo off
setlocal enabledelayedexpansion
set /p "str=请输入:"
set sum=0
:loop
set "char=%str:~0,1%"
for /f "skip=1 delims=:" ...
这个没有用,不管输入什么批处理都会退出
Last edited by tireless on 2008-9-20 at 01:33 PM ]
Originally posted by HAT at 2008-9-20 05:30 AM:
Then use the idea from floor 2
@echo off
setlocal enabledelayedexpansion
set /p "str=Please enter:"
set sum=0
:loop
set "char=%str:~0,1%"
for /f "skip=1 delims=:" ...
This doesn't work. No matter what is entered, the batch processing will exit
Last edited by tireless on 2008-9-20 at 01:33 PM ]
|
|
2008-9-21 07:44 |
|
|
metoo
初级用户
 
积分 195
发帖 93
注册 2006-10-28
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
归根结底就是findstr的正则太肉
In the final analysis, it's just that the regular expression of findstr is too restrictive
|
|
2008-9-21 08:13 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
再试试这个如何?
改一下,支持特殊字符:
@echo off
setlocal enabledelayedexpansion
:bgn
type nul>t_.txt
set "n="&set "count="
set /p str=请输入:
:agn
>>t_.txt echo.!str:~,1!
if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn)
>>t_.txt echo god
for /f "delims=:" %%a in ('findstr /o .* t_.txt') do (
set /a "n+=1","m=n-1"
set "_!n!=%%a"
if !n! geq 2 (
call set /a "var=%%_!n!%%-%%_!m!%%"
if !var! equ 4 (set /a count+=19) else (set /a count+=10)
)
)
echo %count%
goto :bgn
Last edited by moniuming on 2008-9-21 at 10:27 AM ]
How about trying this?
Modify it to support special characters:
@echo off
setlocal enabledelayedexpansion
:bgn
type nul>t_.txt
set "n="&set "count="
set /p str=Please enter:
:agn
>>t_.txt echo.!str:~,1!
if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn)
>>t_.txt echo god
for /f "delims=:" %%a in ('findstr /o .* t_.txt') do (
set /a "n+=1","m=n-1"
set "_!n!=%%a"
if !n! geq 2 (
call set /a "var=%%_!n!%%-%%_!m!%%"
if !var! equ 4 (set /a count+=19) else (set /a count+=10)
)
)
echo %count%
goto :bgn
Last edited by moniuming on 2008-9-21 at 10:27 AM ]
|
|
2008-9-21 10:21 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 19 楼』:
Re 18 楼
使用 LLM 解释/回答一下
计算不正确。
床前明月光,疑是地上霜。举头望明月,低头思故乡。 的计算结果是 240。正确的应该是 456。
The calculation is incorrect. The result of "Bed head bright moon light, suspect is frost on the ground. Raise head to look at bright moon, lower head to think of hometown." is 240. The correct one should be 456.
|
|
2008-9-21 10:36 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
|
2008-9-21 11:33 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 21 楼』:
Re 16楼
使用 LLM 解释/回答一下
15楼代码的运行结果:
C:\Test>test.bat
请输入:床前明月光,疑是地上霜。举头望明月,低头思故乡。
456
能把你的测试用例和测试结果贴出来看看吗?
The running result of the code on floor 15:
C:\Test>test.bat
Please enter: Bed head bright moon light, suspected is frost on the ground. Lift head to look at bright moon, lower head to think of hometown.
456
Can you post your test cases and test results for me to see?
|

 |
|
2008-9-21 11:34 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
额,15 楼的代码有用。计算太慢了,昨晚我以为批处理没有反应,没等结果出来就关掉了...
Uh, the code on the 15th floor is useful. The calculation is too slow. Last night I thought the batch processing didn't respond and closed it before the result came out...
|
|
2008-9-21 11:44 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
经多次测试,20楼的通过各种测试,而且效率还可以,试试?
Last edited by moniuming on 2008-9-21 at 11:55 AM ]
After multiple tests, the 20th floor has passed various tests, and the efficiency is okay. Try it?
Last edited by moniuming on 2008-9-21 at 11:55 AM ]
|
|
2008-9-21 11:53 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
最后一次整合...
20 楼的代码完全不会出错。我想在原基础上再加上一些命令处理,可是我写的代码有点问题,所以再麻烦下各位,顺便整合在一起。
想在原基础上再进行这些处理:
1、还要显示输入的是什么
2、输入后,首先进行这些判断:
如果:
直接回车,则执行命令
输入的是 /h,则执行命令然后退出
输入的是 /s,则执行命令然后退出
输入的是 /r,则执行命令然后退出
再判断下面的:
是否以 /h 开头,如果是,则截取 /h 后面的字符,然后执行命令
是否以 /s 开头,如果是,则截取 /s 后面的字符,然后执行命令
以下是我修改后的代码:
■: 原 20 楼的代码 ■: 我加上的
@echo off
setlocal enabledelayedexpansion
:bgn
del t_.txt 1>nul 2>nul
set "n="&set "count="
set /p str=请输入:
if not defined str goto 11
If %str%==/h 执行命令 & exit
If %str%==/s 执行命令 & exit
If %str%==/r 执行命令 & exit
if /i "%str:~,2%"=="/h" (
set str=%str:~2%
执行命令
goto settext
)
if /i "%str:~,2%"=="/s" (
set str=%str:~2%
执行命令
)
:settext
set Text=%str%
:agn
set st=!str:~,1!
>>t_.txt echo.!st!
if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn)
>>t_.txt echo god
for /f "delims=:" %%a in ('findstr /o .* t_.txt') do (
set /a "n+=1","m=n-1"
set "_!n!=%%a"
if !n! geq 2 (
call set /a "var=%%_!n!%%-%%_!m!%%"
if !var! equ 4 (set /a count+=19) else (set /a count+=10)
)
)
echo %count%
echo %text%
goto :bgn
:11
...
测试结果是,有空格就会出错。
(错误不出在别处,就在我添加的那段里运行中断了)
Last edited by tireless on 2008-9-21 at 01:53 AM ]
Final Integration...
The code on floor 20 is completely error-free. I want to add some command processing on the original basis, but there is something wrong with the code I wrote, so I need to trouble you again, and integrate them together.
I want to perform these processes on the original basis:
1. Also display what is entered
2. After input, first make these judgments:
If:
Press Enter directly, then execute the command
If the input is /h, then execute the command and exit
If the input is /s, then execute the command and exit
If the input is /r, then execute the command and exit
Then judge the following:
If it starts with /h, then intercept the characters after /h, and then execute the command
If it starts with /s, then intercept the characters after /s, and then execute the command
The following is the code I modified:
■: Original code on floor 20 ■: What I added
@echo off
setlocal enabledelayedexpansion
:bgn
del t_.txt 1>nul 2>nul
set "n="&set "count="
set /p str=Please enter:
if not defined str goto 11
If %str%==/h 执行命令 & exit
If %str%==/s 执行命令 & exit
If %str%==/r 执行命令 & exit
if /i "%str:~,2%"=="/h" (
set str=%str:~2%
执行命令
goto settext
)
if /i "%str:~,2%"=="/s" (
set str=%str:~2%
执行命令
)
:settext
set Text=%str%
:agn
set st=!str:~,1!
>>t_.txt echo.!st!
if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn)
>>t_.txt echo god
for /f "delims=:" %%a in ('findstr /o .* t_.txt') do (
set /a "n+=1","m=n-1"
set "_!n!=%%a"
if !n! geq 2 (
call set /a "var=%%_!n!%%-%%_!m!%%"
if !var! equ 4 (set /a count+=19) else (set /a count+=10)
)
)
echo %count%
echo %text%
goto :bgn
:11
...
The test result is that there will be an error if there is a space.
(The error is not elsewhere, just in the part I added that the operation is interrupted)
Last edited by tireless on 2008-9-21 at 01:53 AM ]
|
|
2008-9-21 21:29 |
|
|
zqz0012005
中级用户
  
积分 297
发帖 135
注册 2006-10-21
状态 离线
|
  『第 25 楼』:
使用 LLM 解释/回答一下
If %str%==/h 执行命令 & exit
...
if /i "%str:~,2%"=="/h"
怎么后面知道加引号,前面为何不加
```
If %str%==/h 执行命令 & exit
...
if /i "%str:~,2%"=="/h"
Why is there a quote added at the back, but not at the front?
```
|

hh.exe ntcmds.chm::/ntcmds.htm
 |
|
2008-9-21 22:07 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
怎么后面知道加引号,前面为何不加
加上引号后,输入空格没有问题了。却还有另外的问题:
请输入:(*^__^*) 嘻嘻……
此时不应有 嘻嘻……。
请输入:(**) 嘻嘻
此时不应有 嘻嘻。
请输入:O(∩_∩)O哈哈
此时不应有 O哈哈。
请输入:O(∩_∩)O
此时不应有 O。
是什么原因?
用以下代码做测试:
@echo off
:s
set /p str=请输入:
if not defined str echo 未定义&goto :s
If "%str%"=="/h" echo 执行/h命令&goto :s
If "%str%"=="/s" echo 执行/s命令&goto :s
If "%str%"=="/r" echo 执行/r命令&goto :s
if /i "%str:~,3%"=="/h " (
set str=%str:~3%
echo 执行/h命令
goto showtext
)
if /i "%str:~,3%"=="/s " (
set str=%str:~3%
echo 执行/s命令
)
:showtext
echo %str%
goto s
Last edited by tireless on 2008-9-21 at 02:52 PM ]
Why is there a quote added later, but not earlier?
After adding the quote, there is no problem with entering spaces. But there is another problem:
Please enter:(*^__^*) Hee hee……
At this time, there should be no Hee hee…….
Please enter:(**) Hee hee
At this time, there should be no Hee hee.
Please enter:O(∩_∩)O Haha
At this time, there should be no O Haha.
Please enter:O(∩_∩)O
At this time, there should be no O.
What is the reason?
Test with the following code:
@echo off
:s
set /p str=Please enter:
if not defined str echo Undefined&goto :s
If "%str%"=="/h" echo Execute /h command&goto :s
If "%str%"=="/s" echo Execute /s command&goto :s
If "%str%"=="/r" echo Execute /r command&goto :s
if /i "%str:~,3%"=="/h " (
set str=%str:~3%
echo Execute /h command
goto showtext
)
if /i "%str:~,3%"=="/s " (
set str=%str:~3%
echo Execute /s command
)
:showtext
echo %str%
goto s
Last edited by tireless on 2008-9-21 at 02:52 PM ]
|
|
2008-9-22 09:11 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
试试?
@echo off
Setlocal Enabledelayedexpansion
:s
set "str="
set /p str=请输入:
if not defined str echo 未定义&goto :s
If /i "!str!"=="/h" echo 执行/h命令&goto :s
If /i "!str!"=="/s" echo 执行/s命令&goto :s
If /i "!str!"=="/r" echo 执行/r命令&goto :s
if /i "!str:~,3!"=="/h " (
set "str=!str:~3!"
echo 执行/h命令
goto showtext
)
if /i "!str:~,3!"=="/s " (
set "str=!str:~3!"
echo 执行/s命令
)
:showtext
echo !str!
goto s
Last edited by moniuming on 2008-9-22 at 12:03 PM ]
Try it?
@echo off
Setlocal Enabledelayedexpansion
:s
set "str="
set /p str=Please enter:
if not defined str echo Not defined&goto :s
If /i "!str!"=="/h" echo Execute /h command&goto :s
If /i "!str!"=="/s" echo Execute /s command&goto :s
If /i "!str!"=="/r" echo Execute /r command&goto :s
if /i "!str:~,3!"=="/h " (
set "str=!str:~3!"
echo Execute /h command
goto showtext
)
if /i "!str:~,3!"=="/s " (
set "str=!str:~3!"
echo Execute /s command
)
:showtext
echo !str!
goto s
Last edited by moniuming on 2008-9-22 at 12:03 PM ]
|
|
2008-9-22 11:45 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 28 楼』:
re 27 楼
使用 LLM 解释/回答一下
没问题了。
谢谢大家耐心的帮助。
It's all right. Thanks to everyone for your patient help.
|
|
2008-9-22 12:18 |
|