-----------------------------------
There is the following corresponding relationship:
0123456789 | abcdefghij
It is required to write an interactive batch processing.
-----------------------------------
When inputting 7, the output is as follows:
#######7## | ##c#######
When inputting a5, the output is as follows:
#####5###9 | a###e#####
When inputting 12j, the output is as follows:
012####### | #######hij
-----------------------------------
1 I will give points according to the problem-solving ideas and skills (focusing on ideas).
2 If you don't want to deal with special characters, you can omit the middle | and not output it.
3 Please pay attention to the generality of the code when solving the problem, and try to keep the code concise (consider the problem complicated, and solve the problem simply).
4 When interacting with the human-computer interface for input, you can try to provide convenience for problem-solving as much as possible.
5 There is no need to write the code part for judging the input characters.
-----------------------------------
-----------------------------------
Brother pusofalse was the first to solve this problem on the 15th floor, but his code is obviously too complicated and not general, so only 1 point is added.
I also gave a solution on the 25th floor (the code is still a bit complicated).
There are already multiple solutions (10th floor, 25th floor, 26th floor, 28th floor, 29th floor, 35th floor, 37th floor, 38th floor...),
I still tend to the solution given on the 28th floor (the best solution still needs everyone to evaluate), the code is as follows:
@echo off&setlocal enabledelayedexpansion
set str=0j 1i 2h 3g 4f 5e 6d 7c 8b 9a
set /p code=Please enter characters, separate them with spaces in the middle:
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
I think this code has the characteristics of clear ideas, generality, conciseness, efficiency and so on.
Hereby recommend the code of brother terse as follows:
@echo off&setlocal enabledelayedexpansion
set/p p=Please enter:
set str=27j834fi56a901bghcde
set st=!str!&set pt=!p!
:lp
set ..!p:~%n%,1!=ok&set/a n+=1
set .!str:~,1!=!str:~-1,1!
set str=!str:~1,-1!
if defined str goto lp
:lp1
if defined ..%st:~,1% (set var1=!var1!%st:~,1%&set var2=!.%st:~,1%!!var2!)else (
if defined ..!.%st:~,1%! (set var1=!var1!%st:~,1%&set var2=!.%st:~,1%!!var2!)else set var1=!var1!#&set var2=#!var2!)
set st=!st:~1,-1!&set pt=!pt:~1!
if defined st goto lp1
echo !var1! ^| !var2!
pause
-----------------------------------
Thank you all for your enthusiastic responses to this post, but the only thing that is insufficient is that basically they are all senior members (quya laotu is actually also a veteran member), and there are few traces of new people. I hope that new people all have the spirit of being brave to challenge, and the original intention of me constantly setting questions is also for this.
-----------------------------------
[ Last edited by zw19750516 on 2008-7-13 at 09:44 AM ]
批处理之家新域名:www.bathome.net

