|  | 
 
| everest79 金牌会员
 
       一叶枝头,万树皆春
 
 
 
 积分 2564
 发帖 1127
 注册 2006-12-25
 状态 离线
 | 
| 『楼 主』:
 [求助]命令行下通过四则运算得到绝对值
 
使用 LLM 解释/回答一下 
 
 
大概如下
 set /p a=input
 set /a b=算法
 %b%为输入数字的绝对值
 
 不使用字符替换或IF判断
 
Probably as follows
 set /p a=input
 set /a b=algorithm
 %b% is the absolute value of the input number
 
 Without using character replacement or IF judgment
 
 
 
 |  | 
|  2007-1-17 12:58 |  | 
|  | 
 
| namejm 荣誉版主
 
        batch fan
 
 
 积分 5226
 发帖 1737
 注册 2006-3-10
 来自 成都
 状态 离线
 | 
| 『第 2 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
  最简单的办法是用字符串替换语句,演示代码如下: ——————————————————@echo off
 set input=
 set /p input=请输入实数:
 echo %input:-=%
 pause
 
 
  居然是不要字符替换的,还不允许用if语句,真是太BT了,不知道你这样要求有什么特殊需要。再来一个:
 @echo off
 set input=
 set /p input=请输入实数:
 for /f "tokens=* delims=-" %%i in ("%input%") do echo %%i
 pause
 
 
 Last edited by namejm on 2007-1-17 at 12:33 AM ]
The simplest way is to use a string replacement statement. The demonstration code is as follows: ——————————————————@echo off
 set input=
 set /p input=Please enter a real number:
 echo %input:-=%
 pause
 
 
It turns out that character replacement is not wanted, and the use of if statements is not allowed. It's really too BT. I don't know what special needs you have for such a requirement. Here's another one:
 @echo off
 set input=
 set /p input=Please enter a real number:
 for /f "tokens=* delims=-" %%i in ("%input%") do echo %%i
 pause
 
 
 Last edited by namejm on 2007-1-17 at 12:33 AM ]
 
 
 
 |  
                  |  尺有所短,寸有所长,学好CMD没商量。
 考虑问题复杂化,解决问题简洁化。
 |  | 
|  2007-1-17 13:27 |  | 
|  | 
 
| everest79 金牌会员
 
       一叶枝头,万树皆春
 
 
 
 积分 2564
 发帖 1127
 注册 2006-12-25
 状态 离线
 | 
| 『第 3 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
嘿嘿,版主你作弊,我要通过计算来得到绝对值,想了一下午了 
Hehe, the moderator you cheated, I want to get the absolute value through calculation, I've thought about it all afternoon 
 
 
 |  | 
|  2007-1-17 13:42 |  | 
|  | 
 
| redtek 金牌会员
 
       
 
 
 
 积分 2902
 发帖 1147
 注册 2006-9-21
 状态 离线
 | 
| 『第 4 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
第1种方法: 负负得正原理 @echo off
 
 set /p var=请输入负数:
 set /a var=-%var%
 
 echo 绝对值为: %var%
 
 
计算有小数点儿的数字出错~:) 
计算正数出错:)
 
第2种方法: (负数)-(负数)*2 =(绝对值)
 @echo on
 
 set /p var=请输入负数:
 set /a var=%var%-%var%*2
 
 echo 绝对值为: %var%
 
 
不支持浮点运算。 
只支持求负数的绝对值(输入正数则出错)
Method 1: Principle of Two Negatives Make a Positive @echo off
 
 set /p var=Please enter a negative number:
 set /a var=-%var%
 
 echo The absolute value is: %var%
 
 
There is an error when calculating numbers with decimals ~ : ) 
There is an error when calculating positive numbers : )
 
Method 2: (Negative number) - (Negative number) * 2 = (Absolute value)
 @echo on
 
 set /p var=Please enter a negative number:
 set /a var=%var%-%var%*2
 
 echo The absolute value is: %var%
 
 
Does not support floating-point operations. 
Only supports finding the absolute value of a negative number (errors occur when entering a positive number)
 
 
 
 |  
                  |  Redtek,一个永远在网上流浪的人……
 
 _.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
 |  | 
|  2007-1-17 22:23 |  | 
|  | 
 
| scriptor 银牌会员
 
      
 
 
 积分 1187
 发帖 555
 注册 2006-12-21
 状态 离线
 | 
| 『第 5 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
I got one:
 @echo off
 set /p n="Input any negative number: "
 set /a m=~n+1
 echo The absolute of %n% is: %m%
 pause >nul
 
 It's too easy by using it.
 
 No decimal fraction, but zero is permitted.
 
 Last edited by scriptor on 2007-1-17 at 11:16 AM ]
 
I got one:
 @echo off
 set /p n="Input any negative number: "
 set /a m=~n+1
 echo The absolute of %n% is: %m%
 pause >nul
 
 It's too easy by using it.
 
 No decimal fraction, but zero is permitted.
 
 Last edited by scriptor on 2007-1-17 at 11:16 AM ]
 
 
 
 |  | 
|  2007-1-17 23:30 |  | 
|  | 
 
| qzwqzw 银牌会员
 
      天的白色影子
 
 
 积分 2343
 发帖 636
 注册 2004-3-6
 状态 离线
 | 
|  『第 6 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
一个粗劣的例子
 a取值的上下限各缩小一半
 
 set /a b=(a*2+1)%%2*a
 
A crude example
 Each of the upper and lower limits of the value of a is reduced by half
 
 set /a b=(a*2+1)%%2*a
 
 
 | 此帖被 +22 点积分  点击查看详情 | 评分人:【 everest79 】 | 分数: +4 | 时间:2007-1-18 01:12 |  | 评分人:【 redtek 】 | 分数: +9 | 时间:2007-1-18 02:39 |  | 评分人:【 namejm 】 | 分数: +4 | 时间:2007-1-18 10:23 |  | 评分人:【 lxmxn 】 | 分数: +4 | 时间:2007-1-18 11:10 |  | 评分人:【 minmin888 】 | 分数: +1 | 时间:2007-5-4 10:58 | 
 | 
 
 
 
 |  | 
|  2007-1-17 23:37 |  | 
|  | 
 
| scriptor 银牌会员
 
      
 
 
 积分 1187
 发帖 555
 注册 2006-12-21
 状态 离线
 | 
| 『第 7 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
请把它删除了写错了
 
 Last edited by scriptor on 2007-1-17 at 11:14 AM ]
 
Please delete it. It was written wrong.
 Last edited by scriptor on 2007-1-17 at 11:14 AM ]
 
 
 
 |  | 
|  2007-1-17 23:47 |  | 
|  | 
 
| scriptor 银牌会员
 
      
 
 
 积分 1187
 发帖 555
 注册 2006-12-21
 状态 离线
 | 
| 『第 8 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
请版主把它删除了
 Last edited by scriptor on 2007-1-17 at 11:12 AM ]
 
Please let the moderator delete it.
 Last edited by scriptor on 2007-1-17 at 11:12 AM ]
 
 
 
 |  | 
|  2007-1-17 23:51 |  | 
|  | 
 
| qzwqzw 银牌会员
 
      天的白色影子
 
 
 积分 2343
 发帖 636
 注册 2004-3-6
 状态 离线
 | 
| 『第 9 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
scriptor兄
 给你两个建议
 
 1、多用中文
 
 2、多做测试
 
Brother scriptor
 Here are two suggestions for you
 
 1. Use more Chinese
 2. Do more testing
 
 
 
 |  | 
|  2007-1-17 23:59 |  | 
|  | 
 
| scriptor 银牌会员
 
      
 
 
 积分 1187
 发帖 555
 注册 2006-12-21
 状态 离线
 | 
| 『第 10 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by qzwqzw at 2007-1-17 10:59:scriptor兄
 
 给你两个建议
 
 1、多用中文
 
 2、多做测试
 
你是说8楼的代码吗? 
对不起,搞错了,那个只能计算奇数
 
谢谢你了
 
我一时性急就发过来了 
Originally posted by qzwqzw at 2007-1-17 10:59:Brother Scriptor
 
 Here are two suggestions for you
 
 1. Use more Chinese
 2. Do more testing
 
You mean the code on floor 8? 
Sorry, I made a mistake, that one can only calculate odd numbers
 
Thank you 
I was in a hurry and sent it over 
 
 
 |  | 
|  2007-1-18 00:09 |  | 
|  | 
 
| qzwqzw 银牌会员
 
      天的白色影子
 
 
 积分 2343
 发帖 636
 注册 2004-3-6
 状态 离线
 | 
| 『第 11 楼』:
 不尽如此
 
使用 LLM 解释/回答一下 
 
 
对于#4中的 ~n+1 代码,不知你是否拿正整数做过测试?
 另外保持版面的简洁是我们共同的义务
 
Have you tested the ~n+1 code in #4 with positive integers? 
 In addition, keeping the layout concise is our common obligation
 
 
 
 |  | 
|  2007-1-18 00:15 |  | 
|  | 
 
| scriptor 银牌会员
 
      
 
 
 积分 1187
 发帖 555
 注册 2006-12-21
 状态 离线
 | 
| 『第 12 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
我在那里已经说明了:@echo off
 set /p n="Input any negative number: "
 是输入负数。
 
 谢谢。记住了
 我发现这几天来我犯了很多的错误啊。
 真的不好意思再发帖子了
 
I have stated there:@echo off
 set /p n="Input any negative number: "
 is to input a negative number.
 
 Thanks. Remembered
 I found that I made many mistakes these days.
 Really embarrassed to post again
 
 
 
 |  | 
|  2007-1-18 00:19 |  | 
|  | 
 
| everest79 金牌会员
 
       一叶枝头,万树皆春
 
 
 
 积分 2564
 发帖 1127
 注册 2006-12-25
 状态 离线
 | 
| 『第 13 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by qzwqzw at 2007-1-17 10:37 AM:一个粗劣的例子
 
 a取值的上下限各缩小一半
 
 set /a b=(a*2+1)%%2*a
 
谢谢qzwqzw,看来我把问题复杂化了 
Originally posted by qzwqzw at 2007-1-17 10:37 AM:A crude example
 
 Shrink the upper and lower limits of a by half each
 
 set /a b=(a*2+1)%%2*a
 
Thank you qzwqzw, it seems I overcomplicated the problem 
 
 
 |  | 
|  2007-1-18 01:13 |  | 
|  | 
 
| namejm 荣誉版主
 
        batch fan
 
 
 积分 5226
 发帖 1737
 注册 2006-3-10
 来自 成都
 状态 离线
 | 
| 『第 14 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
  qzwqzw 的思路不错,PF。 
qzwqzw's idea is good, PF. 
 
 
 
 |  
                  |  尺有所短,寸有所长,学好CMD没商量。
 考虑问题复杂化,解决问题简洁化。
 |  | 
|  2007-1-18 10:26 |  | 
|  | 
 
| tghksj 社区乞丐
 
 此图片另存后死机
 
 
 
 积分 -49
 发帖 90
 注册 2006-12-2
 状态 离线
 | 
| 『第 15 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
轻轻的问一下:
 qzwqzw老师
 
 可不可以利用SET的2进制赋值符号进行转换呢??
 
 Last edited by tghksj on 2007-1-17 at 10:50 PM ]
 
Gently ask:
 Teacher qzwqzw
 
 Can we use the binary assignment symbol of SET for conversion??
 
 [[i] Last edited by tghksj on 2007-1-17 at 10:50 PM [/i]]
 
 
 
 
 |  
                  |  我的网络笔记本.[color=Red]非联系本人请勿访问![/color]http://w.vicp.net[img]http://zhenlove.com.cn/cndos/fileup/files/QM2.jpg[/img]
 |  | 
|  2007-1-18 11:38 |  |