China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 07:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Symmetric output bonus question (challenging) View 4,189 Replies 64
Original Poster Posted 2008-07-10 21:16 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline

-----------------------------------
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
Floor 2 Posted 2008-07-10 21:41 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Is it possible to input a situation where letters and numbers are interleaved, like 2a5f?
致精致简!
Floor 3 Posted 2008-07-10 21:42 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
It's possible, and it doesn't affect anything.
批处理之家新域名:www.bathome.net
Floor 4 Posted 2008-07-10 22:18 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
What about inputting e5?

==!
It's quite difficult and requires a lot of mental effort.

[ Last edited by wxcute on 2008-7-10 at 10:29 PM ]
┌───────┐
├→学习→实践→┤
└───────┘
Floor 5 Posted 2008-07-10 22:27 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
This question doesn't seem to be for beginners.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 6 Posted 2008-07-10 22:38 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It's really brain - consuming. Finally, it's written. The code is relatively bloated. Let's take a look at the novices'...
致精致简!
Floor 7 Posted 2008-07-10 22:41 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The first reaction is to reverse the string, I don't know if the idea is correct.
Floor 8 Posted 2008-07-10 23:02 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by HAT at 2008-7-10 22:41:
The first reaction is to reverse the string, not sure if the idea is correct.

This idea is correct, but there are various solutions.
批处理之家新域名:www.bathome.net
Floor 9 Posted 2008-07-10 23:10 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
There are so many varieties, and just one variety has already made my head big...
致精致简!
Floor 10 Posted 2008-07-11 00:37 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
It's really difficult... But almost successful, it's complicated, way too complicated...
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 11 Posted 2008-07-11 00:47 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Hehe, when I first came up with this question, I didn't expect it to be so difficult!
批处理之家新域名:www.bathome.net
Floor 12 Posted 2008-07-11 01:26 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Finally succeeded... Nearly 4 hours of effort... - -|||
Complicated...
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 13 Posted 2008-07-11 01:42 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by pusofalse at 2008-7-11 01:26:
Finally succeeded... Nearly 4 hours of effort... - -|||
Complicated...

Bro, did you think it was too complicated?
ps: You can post your code.

[ Last edited by zw19750516 on 2008-7-11 at 01:44 AM ]
批处理之家新域名:www.bathome.net
Floor 14 Posted 2008-07-11 01:44 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Maybe...I didn't have any ideas for more than an hour...
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 15 Posted 2008-07-11 01:45 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Originally posted by zw19750516 at 2008-7-11 01:42 AM:

Is the brother overcomplicating things?
ps: You can post your code.

[ Last edited by zw19750516 on 2008-7-11 at 01:44 AM ]

Maybe... I had no idea for more than an hour...
After writing it and taking a look, there's no new idea...

@echo off&setlocal enabledelayedexpansion
set str=0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j
set str1=%str: =%
set n=10
set letter=%str:~19%
set num=%str:~,19%
for %%a in (%letter%) do (
set/a n-=1
set !n!=%%a
set %%a=!n!
)
set/p var=Input:
set var3=%var3%
:pu
if defined var3 (
set var4=!var3:~,1!
if !var4! leq 9 set "shuzi=!shuzi!!var4! "
if !var4! gtr 9 call :shuzi
set var3=!var3:~1!
goto pu
)
goto lp
:shuzi
set "shuzi=!shuzi!!%var4%! "
goto :eof


:lp
if defined str1 (
set str2=!str1:~,1!
for %%a in (%shuzi%) do if "-!str2!" equ "-%%a" goto next
for %%a in (%shuzi%) do if "-!str2!" neq "-%%a" set str2=#
:next
set pus=!pus!!str2!
set str1=!str1:~1!
goto lp
)
set will=%pus:~,10%
:will
if defined will (
set wil=!will:~-1!
call :w
set will=!will:~0,-1!
goto will
)
echo %pus:~,10%^|%false%
pause>nul&exit/b


:w
if defined %wil% (set false=!false!!%wil%!) else set false=!false!%wil%
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
bat-zw +1 2008-07-11 01:50
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
1 2 3 5 Next ›
Forum Jump: