|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
晕。。。
ps:兄弟的代码不通用啊,如果两边都是字母或汉字怎么办?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
Wow. . .
ps: Brother's code is not universal. What if both sides are letters or Chinese characters?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 01:46 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
Originally posted by zw19750516 at 2008-7-11 01:46 AM:
晕。。。
ps:兄弟的代码不通用啊,如果两边都是字母或汉字怎么办?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
还请多指教!~
Originally posted by zw19750516 at 2008-7-11 01:46 AM:
Dizzy...
ps: Brother's code is not universal. What if both sides are letters or Chinese characters?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
Please give more advice!~
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-7-11 01:52 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
提示,以中间为界同时从两边截取字符
Tips: intercept characters from both sides at the same time with the middle as the boundary
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 01:55 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
Originally posted by zw19750516 at 2008-7-11 01:46:
晕。。。
ps:兄弟的代码不通用啊,如果两边都是字母或汉字怎么办?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
两边都是字母?
这只能怪你出题不谨慎了。。
Originally posted by zw19750516 at 2008-7-11 01:46:
Dizzy...
ps: Brother's code is not universal. What if both sides are letters or Chinese characters?
Last edited by zw19750516 on 2008-7-11 at 01:49 AM ]
Both sides are letters?
This can only be blamed on your carelessness in setting the question.
|

致精致简! |
|
2008-7-11 01:57 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
果真是我想太太太复杂了。。。这题做到一半我是想放弃的,FAITH。。。
现在再做的话,我怕我果真会放弃了,如此的一个题目,想的脊椎都疼了~
It really is that I thought too, too complicated... I wanted to give up halfway through this problem, FAITH... Now if I do it again, I'm afraid I'll really give up. Such a problem makes my spine hurt when I think about it~
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-7-11 02:01 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-7-11 01:57:
两边都是字母?
这只能怪你出题不谨慎了。。
我只是说明代码要提高通用性啊,没别的意思,本题他是已经做出来了,这个我不否认的。
Originally posted by 26933062 at 2008-7-11 01:57:
Both sides are letters?
This can only blame you for not being careful in setting the question.
I just explained that the code should improve generality, and there's no other meaning. For this question, he has already solved it, and I don't deny that.
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 02:02 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
Originally posted by pusofalse at 2008-7-11 02:01:
果真是我想太太太复杂了。。。这题做到一半我是想放弃的,FAITH。。。
现在再做的话,我怕我果真会放弃了,如此的一个题目,想的脊椎都疼了~
胜利往往是跟在你感觉再也挺不住的那一刻之后的。
ps:兄弟们,我先睡觉了,明天还要上班,期待有人写出高效通用的代码(我的就先不发了)。。。
Last edited by zw19750516 on 2008-7-11 at 02:08 AM ]
Originally posted by pusofalse at 2008-7-11 02:01:
It's really that I thought too, too complicated... I wanted to give up halfway through this problem, FAITH...
Now if I do it again, I'm afraid I will really give up. Such a problem makes my spine hurt thinking about it~
Victory often follows right after the moment when you feel you can't hold on any longer.
ps: Brothers, I'm going to sleep first. I have to go to work tomorrow. Looking forward to someone writing efficient and general-purpose code (mine won't be posted first)...
Last edited by zw19750516 on 2008-7-11 at 02:08 AM ]
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 02:04 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
我想没这么长吧 报到
I think it's not that long. Sign in
|

简单!简单!再简单! |
|
2008-7-11 02:46 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2008-7-11 02:46:
我想没这么长吧 报到
但解题的代码肯定都不会短,我想应该不能在10行内解决问题。
But the code for solving the problem must not be short. I think it should not be solvable within 10 lines.
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 10:02 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
看来此题确实有点难度,我先公布本人所想的比较复杂的一种方法吧:
@echo off&setlocal enabledelayedexpansion
set str=0123456789abcdefghij
:lp
set a=%str:~,1%&set /a n+=1
set .%n%=%a%&set _%n%=!str:~-1,1!&set str=%str:~1,-1%
if defined str goto lp
set /p code=please enter the code:
:loop
set a=%code:~,1%&set var=%var% !a!&set code=%code:~1%
if defined code goto loop
for /l %%a in (1,1,%n%) do (
for %%i in (%var%) do (
if "!.%%a!" equ "%%i" set flag=a
if "!_%%a!" equ "%%i" set flag=a
)
if defined flag (
set str1=!str1!!.%%a!&set str2=!_%%a!!str2!&set "flag="
) else (
set str1=!str1!#&set str2=#!str2!
))
cls&echo %str1% ^| %str2%&pause>nul
It seems that this problem is indeed a bit difficult. I'll first公布 my thought - out relatively complex method:
@echo off&setlocal enabledelayedexpansion
set str=0123456789abcdefghij
:lp
set a=%str:~,1%&set /a n+=1
set .%n%=%a%&set _%n%=!str:~-1,1!&set str=%str:~1,-1%
if defined str goto lp
set /p code=please enter the code:
:loop
set a=%code:~,1%&set var=%var% !a!&set code=%code:~1%
if defined code goto loop
for /l %%a in (1,1,%n%) do (
for %%i in (%var%) do (
if "!.%%a!" equ "%%i" set flag=a
if "!_%%a!" equ "%%i" set flag=a
)
if defined flag (
set str1=!str1!!.%%a!&set str2=!_%%a!!str2!&set "flag="
) else (
set str1=!str1!#&set str2=#!str2!
))
cls&echo %str1% ^| %str2%&pause>nul
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 11:49 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
    『第 26 楼』:
使用 LLM 解释/回答一下
确实够绕人的。!花费了我不少时间。。。
前后共想出三种方法,第一种没通用性,后两种比较通用。
总的来说感觉思路没有zw19750516的清晰。。。 已经迷糊了。被绕晕了。。。
代码一、
左边的必须是数字。(不通用、仅针对顶楼的题目)
@echo off&setlocal enabledelayedexpansion
echo.&set /p num= 请输入 &cls
set "str=a b c d e f g h i j"
set "var1=##########"
set /a n=10
for %%a in (%str%) do (
set /a n-=1&set .%%a=!n!&set .!n!=!n!&set "_!n!=%%a"
)
for /l %%a in (0 1 9) do (
if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
)
for %%a in (!num2!) do (
set /a n=!.%%a!+1
call set "var1=%%var1:~0,!.%%a!%%!.%%a!%%var1:~!n!%%"
)
for /l %%a in (0 1 9) do (
if "!var1:~%%a,1!"=="#" (set var2=#!var2!) else set "var2=!_%%a!!var2!"
)
echo.&echo !var1! !var2!
pause>nul
代码二、
通用点的,不局限于数字、左右两边可以是任意字符但不能有重复。
@echo off&setlocal enabledelayedexpansion
set "str1=abcdefghij"&set "str2=tsrqponmlk"
for /l %%a in (0 1 9) do (
set ".!str1:~%%a,1!=!str1:~%%a,1!"
set ".!str2:~%%a,1!=!str1:~%%a,1!"
set "_!str1:~%%a,1!=#"
set "_!str2:~%%a,1!=#"
)
echo !str1! klmnopqrst
echo.&set /p num= 请输入 &cls&echo !num!
echo.&echo !str1! klmnopqrst
set num=!num: =!
for /l %%a in (0 1 9)do if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
for %%a in (!num2!) do set _%%a=!.%%a!&set "_!.%%a!=!.%%a!"
for /l %%a in (0 1 9) do call set "var1=!var1! %%_!str1:~%%a,1!%%"
set /a nnn=-1
for %%a in (!var1!) do (
set /a nnn+=1
if "%%a"=="#" (set var2=#!var2!) else call set "var2=%%str2:~!nnn!,1%%!var2!"
)
echo.&echo !var1: =! !var2!
pause>nul
代码三、
@echo off&setlocal enabledelayedexpansion
set "str1=abcdefghij"&set "str2=tsrqponmlk"
set var1=##########&set var2=!var1!
echo !str1! klmnopqrst
echo.&set /p num= 请输入 &cls&echo 你输入的是 !num!
echo.&echo !str1! klmnopqrst
set num=!num: =!
for /l %%a in (0 1 9)do if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
for /l %%a in (0 1 9) do (
set /a mmm=%%a+1
set ".!str1:~%%a,1!=!mmm!"
set ".!str2:~%%a,1!=!mmm!"
)
for %%a in (!num2!) do (
set /a hhh=!.%%a!-1
call set var1=%%var1:~0,!hhh!%%%%str1:~!hhh!,1%%%%var1:~!.%%a!%%
call set var2=%%var2:~0,!hhh!%%%%str2:~!hhh!,1%%%%var2:~!.%%a!%%
)
for /l %%a in (0 1 9) do set var3=!var2:~%%a,1!!var3!
echo.&echo !var1! !var3!
pause>nul
It's really confusing. It took me quite a while...
There are three methods thought out in total. The first one is not universal, and the latter two are relatively universal.
Generally speaking, I feel that the idea is not as clear as zw19750516's... I'm confused. Got bamboozled...
Code One:
The left side must be a number. (Not universal, only for the topic in the first post)
@echo off&setlocal enabledelayedexpansion
echo.&set /p num= Please enter &cls
set "str=a b c d e f g h i j"
set "var1=##########"
set /a n=10
for %%a in (%str%) do (
set /a n-=1&set .%%a=!n!&set .!n!=!n!&set "_!n!=%%a"
)
for /l %%a in (0 1 9) do (
if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
)
for %%a in (!num2!) do (
set /a n=!.%%a!+1
call set "var1=%%var1:~0,!.%%a!%%!.%%a!%%var1:~!n!%%"
)
for /l %%a in (0 1 9) do (
if "!var1:~%%a,1!"=="#" (set var2=#!var2!) else set "var2=!_%%a!!var2!"
)
echo.&echo !var1! !var2!
pause>nul
Code Two:
More universal, not limited to numbers, both left and right sides can be any characters but no duplicates.
@echo off&setlocal enabledelayedexpansion
set "str1=abcdefghij"&set "str2=tsrqponmlk"
for /l %%a in (0 1 9) do (
set ".!str1:~%%a,1!=!str1:~%%a,1!"
set ".!str2:~%%a,1!=!str1:~%%a,1!"
set "_!str1:~%%a,1!=#"
set "_!str2:~%%a,1!=#"
)
echo !str1! klmnopqrst
echo.&set /p num= Please enter &cls&echo !num!
echo.&echo !str1! klmnopqrst
set num=!num: =!
for /l %%a in (0 1 9)do if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
for %%a in (!num2!) do set _%%a=!.%%a!&set "_!.%%a!=!.%%a!"
for /l %%a in (0 1 9) do call set "var1=!var1! %%_!str1:~%%a,1!%%"
set /a nnn=-1
for %%a in (!var1!) do (
set /a nnn+=1
if "%%a"=="#" (set var2=#!var2!) else call set "var2=%%str2:~!nnn!,1%%!var2!"
)
echo.&echo !var1: =! !var2!
pause>nul
Code Three:
@echo off&setlocal enabledelayedexpansion
set "str1=abcdefghij"&set "str2=tsrqponmlk"
set var1=##########&set var2=!var1!
echo !str1! klmnopqrst
echo.&set /p num= Please enter &cls&echo You entered is !num!
echo.&echo !str1! klmnopqrst
set num=!num: =!
for /l %%a in (0 1 9)do if not "!num:~%%a,1!"=="" set num2=!num2! !num:~%%a,1!
for /l %%a in (0 1 9) do (
set /a mmm=%%a+1
set ".!str1:~%%a,1!=!mmm!"
set ".!str2:~%%a,1!=!mmm!"
)
for %%a in (!num2!) do (
set /a hhh=!.%%a!-1
call set var1=%%var1:~0,!hhh!%%%%str1:~!hhh!,1%%%%var1:~!.%%a!%%
call set var2=%%var2:~0,!hhh!%%%%str2:~!hhh!,1%%%%var2:~!.%%a!%%
)
for /l %%a in (0 1 9) do set var3=!var2:~%%a,1!!var3!
echo.&echo !var1! !var3!
pause>nul
|

致精致简! |
|
2008-7-11 12:11 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
说老实话,我看你的化码看晕了。。。强人居然想出了三种方法。
思路突出这处在于巧妙运用了变量赋值。
缺陷我想还是在代码过于繁杂上。
Last edited by zw19750516 on 2008-7-11 at 01:02 PM ]
To be honest, I'm confused by your code... The expert actually came up with three methods.
The idea highlights that this lies in the clever use of variable assignment.
The flaw I think is still in the complexity of the code.
Last edited by zw19750516 on 2008-7-11 at 01:02 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 12:15 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
再给出本人有点取巧的代码(输入时必须按如1 a f 4这样的方式):
@echo off&setlocal enabledelayedexpansion
set str=0j 1i 2h 3g 4f 5e 6d 7c 8b 9a
set /p code=请输入字符,中间请用空格格开:
for %%a in (%str%) do (set a=%%a
for %%i in (%code%) do (
if "%%i" equ "!a:~,1!" set flag=a
if "%%i" equ "!a:~1!" set flag=a
)
if defined flag (
set str1=!str1!!a:~,1!&set str2=!a:~1!!str2!&set "flag="
) else (
set str1=!str1!#&set str2=#!str2!
))
cls&echo %str1% ^| %str2%&pause>nul
Here is another code I used a bit cleverly (when inputting, it must be in the form like 1 a f 4):
@echo off&setlocal enabledelayedexpansion
set str=0j 1i 2h 3g 4f 5e 6d 7c 8b 9a
set /p code=Please enter characters, separated by spaces in between:
for %%a in (%str%) do (set a=%%a
for %%i in (%code%) do (
if "%%i" equ "!a:~,1!" set flag=a
if "%%i" equ "!a:~1!" set flag=a
)
if defined flag (
set str1=!str1!!a:~,1!&set str2=!a:~1!!str2!&set "flag="
) else (
set str1=!str1!#&set str2=#!str2!
))
cls&echo %str1% ^| %str2%&pause>nul
|

批处理之家新域名:www.bathome.net |
|
2008-7-11 12:21 |
|
|
pusofalse
银牌会员
    
积分 1604
发帖 646
注册 2008-4-13
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
看了前辈们的代码,惭愧之至。。。
After seeing the codes of seniors, I feel extremely ashamed...
|

心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^ |
|
2008-7-11 13:09 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
再来一个,思路清晰点的。
@echo off&setlocal enabledelayedexpansion
set "str1= 0 1 2 3 4 5 6 7 8 9"
set "str2= j i h g f e d c b a"
echo.&set /p num= 请输入 &cls&set num=!num: =!
for %%a in (!str1! !str2!) do set num=!num:%%a= %%a!
for %%a in (%str1%) do set /a wei+=1,weis=wei*2
for /l %%a in (1 2 !weis!) do (
set ".!str1:~%%a,1!=!str2:~%%a,1!"
set ".!str2:~%%a,1!=!str1:~%%a,1!"
)
for %%a in (!num!)do set _%%a=a&set _!.%%a!=a
for %%a in (!str1!)do if defined _%%a (set var1=!var1!%%a) else set "var1=!var1!#"
for %%a in (!str2!)do if defined _%%a (set var2=%%a!var2!) else set "var2=#!var2!"
echo.&echo !var1! !var2!
pause>nul
Last edited by 26933062 on 2008-7-11 at 04:14 PM ]
Another one, with a clear train of thought.
@echo off&setlocal enabledelayedexpansion
set "str1= 0 1 2 3 4 5 6 7 8 9"
set "str2= j i h g f e d c b a"
echo.&set /p num= Please enter &cls&set num=!num: =!
for %%a in (!str1! !str2!) do set num=!num:%%a= %%a!
for %%a in (%str1%) do set /a wei+=1,weis=wei*2
for /l %%a in (1 2 !weis!) do (
set ".!str1:~%%a,1!=!str2:~%%a,1!"
set ".!str2:~%%a,1!=!str1:~%%a,1!"
)
for %%a in (!num!)do set _%%a=a&set _!.%%a!=a
for %%a in (!str1!)do if defined _%%a (set var1=!var1!%%a) else set "var1=!var1!#"
for %%a in (!str2!)do if defined _%%a (set var2=%%a!var2!) else set "var2=#!var2!"
echo.&echo !var1! !var2!
pause>nul
Last edited by 26933062 on 2008-7-11 at 04:14 PM ]
|

致精致简! |
|
2008-7-11 15:18 |
|