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 06:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Symmetric output bonus question (challenging) View 4,187 Replies 64
Floor 46 Posted 2008-07-12 13:55 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
The old-fashioned person thinks too much. Only the problem-solving code for specific issues needs to consider many issues in the application, such as exception handling, interface optimization, default values, and so on. But what we are discussing now is just some prototypical code, which can't be talked about how to apply it at all. We just need to abstract the core of the problem and then solve it.
Floor 47 Posted 2008-07-13 03:11 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
No need to enter spaces

@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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
bat-zw +9 2008-07-13 09:34
简单!简单!再简单!
Floor 48 Posted 2008-07-13 09:33 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
This is correct.
Brother, this if defined ..!.%st:~,1%! is really amazing, I've learned it.
批处理之家新域名:www.bathome.net
Floor 49 Posted 2008-07-13 09:53 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Still need to pick some flaws.

I don't understand the others, just this line set str=27j834fi56a901bghcde

It still doesn't seem very universal.

Comrades, please forgive me, my level is not good, I can only pick flaws.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 50 Posted 2008-07-13 10:14 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by quya at 2008-7-13 09:53:
Still need to pick some flaws.

I can't understand the others, just this line set str=27j834fi56a901bghcde

It still seems not very universal.

Comrades, please forgive me, my level is not good, I can only pick flaws.

Old-fashioned, this set is based on the situation. For example, if it is to be symmetrical with numbers and letters, then set str=numbers+letters. If it is to be symmetrical with numbers and Chinese characters, then set str=numbers+Chinese characters. If the symmetrical relationship is irregular, then it is set as terse brother did.
批处理之家新域名:www.bathome.net
Floor 51 Posted 2008-07-13 10:26 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by zw19750516 at 2008-7-13 10:14 AM:

Old-fashioned, this set is based on the situation. For example, if you want to be symmetrical with numbers and letters, then set str=numbers+letters. If you want to be symmetrical with numbers and Chinese characters, then set str=numbers+Chinese characters. If the symmetrical relationship is irregular, then set it as terse brother did.


My understanding of your question is that symmetry has nothing to do with numbers and letters.

As long as you find the input value, it will be displayed at that position, and then displayed at the symmetrical position of that position. Both numbers and letters can be in random order.

So I am very confused about your problem-solving ideas.

For example, the following is random and repeated, (there are 2 zeros), it can also be displayed correctly.

But I currently can't solve the problem of spaces in the original characters. Spaces can be entered.

@echo off
set/p input=Please enter:
set "string=012t457689aycd0fghi3"
set num=
:pro1
set /a num+=1
set strtmp=%string:~0,1%%string:~-1%
set str%num%=##
rem The following sentence is an application of findstr class
echo %input%|findstr >nul&&set str%num%=%strtmp%
set string=%string:~1,-1%
if not defined string goto pro2
goto pro1

:pro2
setlocal enabledelayedexpansion
set str_1=x
for /l %%i in (1,1,%num%) do call set str_1=!str_1:~0,-1!%%str%%i%%
for /l %%i in (1,1,%num%) do call set str_2=%%str%%i%%!str_2:~1!
echo %str_1:~,-1% ^| %str_2:~1,-2%

pause


[ Last edited by quya on 2008-7-13 at 10:35 AM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 52 Posted 2008-07-13 10:39 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
It can be out of order. You can even generate it through code, such as:

@echo off
set code=0123456789abcdefghijklmnopqrstuvwxyz&set n=36
:again
set /a a=%random%%%n%
call,set a=%%code:~%a%,1%%
call,set code=%%code:%a%=%%
set str=%str%%a%&set /a n-=1
if %n% neq 16 goto again
echo %str%&pause>nul
批处理之家新域名:www.bathome.net
Floor 53 Posted 2008-07-13 10:55 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Then the original poster uses your scrambling to re-examine all the solutions.

The program can only modify the line "set code=arbitrary characters". The meaning of arbitrary characters is that what was originally given, just write that.

[ Last edited by quya on 2008-7-13 at 10:58 AM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 54 Posted 2008-07-13 11:13 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Hehe, the old-fashioned person is really persistent,
You can try the code on floor 38. It has handled human-computer interaction, and you can input without spaces or with spaces.
The shortcoming is: there should be no duplicates in any characters.
致精致简!
Floor 55 Posted 2008-07-13 11:32 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by 26933062 at 2008-7-13 11:13 AM:
Hehe, Laotu is really persistent,
You can try the code on floor 38,
It has handled human-computer interaction, you can not enter spaces or can enter.
The shortcoming is: There should be no duplicates in any characters.


Tried when set "str=012t456789abcd6fghi3"

Entering 36 cannot display correctly.

But my code on floor 37 is completely accurate, finally won over the masters.

Just feel that I'm not too stupid, no other meaning.

[ Last edited by quya on 2008-7-13 at 11:34 AM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 56 Posted 2008-07-13 11:42 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by quya at 2008-7-13 11:32:


Tried it. When set "str=012t456789abcd6fghi3"

Entering 36 does not display correctly.

And my code on floor 37 is completely accurate, finally winning over the experts.

Just feel that I'm not too stupid...

It's already said that there can't be duplicates. There are two 6s here?
致精致简!
Floor 57 Posted 2008-07-13 19:38 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Another idea, this should be the simplest one. Not even using a delay variable.

@echo off
set/p input=Please enter:
set string=0123456789abcdefghij
set "str= "

:loop
set str=%string:~-1%%str%%string:~0,1%
echo %input%|findstr >nul||set str=#%str:~1,-1%%#
set string=%string:~1,-1%
if not defined string goto end
goto loop

:end
for /f "tokens=1,2 delims= " %%i in ("%str%") do echo %%j ^| %%i
pause


Actually I want to use delay variables, but I don't know how to use them. At first I thought of writing like the following.

setlocal EnableDelayedExpansion
set string=0123456789abcdefghij
for /l %%i in (1,1,10) do (
set string=!string:~1,-1!
echo !string!
if not defined string goto end)


My expected result is that the variable String gradually becomes shorter, but the first step is not successful, and then the subsequent ideas are all messed up. I really don't understand why I can't achieve the result, please experts give pointers, thank you!

[ Last edited by quya on 2008-7-14 at 10:39 AM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 58 Posted 2008-07-14 08:38 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Old-fashioned. Efficiency is the first consideration in code, and simplicity is the second. Your solution has an efficiency issue, and at the same time ('echo %str%') can be modified to ("%str%").
批处理之家新域名:www.bathome.net
Floor 59 Posted 2008-07-14 10:28 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Is there an efficiency issue with such a simple code in floor 57? Please briefly analyze it, thanks.

%str% has been modified as you suggested, but I still don't understand why. Originally, I just wrote %str%, and the program treated this variable as a file, so I used ECHO. I didn't know I could add "".

[ Last edited by quya on 2008-7-14 at 10:41 AM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 60 Posted 2008-07-14 10:39 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
The efficiency issue is here: echo %input%|findstr [%string:~-1%%string:~0,1%]>nul||set str=#%str:~1,-1%%#
In batch processing, try to use if for judgment as much as possible and use findstr less.
批处理之家新域名:www.bathome.net
Forum Jump: