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 18:18
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Text output~ View 2,803 Replies 47
Original Poster Posted 2008-05-06 22:44 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Transferred from Batch Processing Home

a.txt:
ababababababababa


Output:
ababababababababa
aba a aba ab b b
a a ab a b
a ab b
a
The positions of the spaces are randomly generated, but the same letter is in the same column vertically...
Floor 2 Posted 2008-05-07 11:00 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```batch
@echo off&setlocal enabledelayedexpansion
set str=ababababababababa
echo %str%
:begin
set n=0&set m=0&set "var="
set /a a=%random%%%17+1,b=%random%%%17+1,c=%random%%%17+1
if %a% equ %b% goto begin
if %a% equ %c% goto begin
if %b% equ %c% goto begin
:lp
set /a n+=1
for %%i in (%a% %b% %c%) do if %%i equ %n% set m=1
if %m% equ 0 (
set var=!var!%str:~,1%
) else (
set "var=!var! "
)
set str=%str:~1%&set m=0
if defined str goto lp
if "!var!"==" " pause>nul&goto :eof
echo !var!
set str=!var!&goto begin
```

[ Last edited by zw19750516 on 2008-5-7 at 11:01 AM ]
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-05-07 11:52 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```@echo off&setlocal enabledelayedexpansion
set str=ababababababababa
echo %str%
:begin
set n=0&set m=0&set x=0&set "var="
:set
set /a a=%random%%%17+1
for %%i in (%code%) do if %%i equ %a% goto set
set /a x+=1&set code=%code% %a%
if %x% lss 3 goto set
:lp
set /a n+=1
for %%i in (%code%) do if %%i equ %n% set m=1
if %m% equ 0 (
set var=!var!%str:~,1%
) else (
set "var=!var! "
)
set str=%str:~1%&set m=0
if defined str goto lp
if "!var!"==" " pause>nul&goto :eof
echo !var!
set str=!var!&goto begin
```
批处理之家新域名:www.bathome.net
Floor 4 Posted 2008-05-07 12:02 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The real requirement of this question is that the total number of a and b is 60, and the first letter of the first row is also random and not fixed as a, and the total number of letters in the first row is also random.

[ Last edited by 26933062 on 2008-5-7 at 12:04 PM ]
致精致简!
Floor 5 Posted 2008-05-07 12:04 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Regarding the question of the original poster, my code can already achieve it, but I don't know what the original question was. Can the LS post it?
批处理之家新域名:www.bathome.net
Floor 6 Posted 2008-05-07 12:07 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Requirements:
Do not generate temporary files, and generate the sample format file as provided by the original poster.
Specific requirements:
The total number of a and b is 60, and the total number of letters per line and their positions are random
致精致简!
Floor 7 Posted 2008-05-07 12:13 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
The conditions seem not enough. How many characters at most per line? If there is no such condition, it would have been done in one line.
批处理之家新域名:www.bathome.net
Floor 8 Posted 2008-05-07 12:16 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
What is required is randomness. If possible, it could be one line. It should be generating a or b one by one. The total number is 60.
致精致简!
Floor 9 Posted 2008-05-07 12:47 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```batch>
echo off
set "str=ab " & set m=0
:begin
set /a a=%random%%%60+1
set "var="
:lp
set /a b=%random%%%3
call,set c=%%str:~%b%,1%%
if not "%c%"==" " set /a m+=1
set /a n+=1 & set var=%c%%var%
if %n% lss %a% goto lp
echo.%var%
if %m% lss 60 goto begin
pause>nul
```
批处理之家新域名:www.bathome.net
Floor 10 Posted 2008-05-07 14:15 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Have you tested the ls? What is needed is the format of the top post.
致精致简!
Floor 11 Posted 2008-05-07 15:31 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
&& According to brother's meaning, it is to first randomly generate a string composed of a and b with the total number of characters less than 60, and then replace three characters in the string with spaces line by line, and terminate when the total number of characters (excluding spaces) reaches 60. But I think there will be problems here, because there will always be a situation where there are not enough three characters in one line, and at the same time, the situation where the total number of characters in the second line exceeds 60 will occur. Moreover, it is really too difficult to implement the above!

[ Last edited by zw19750516 on 2008-5-7 at 03:32 PM ]
批处理之家新域名:www.bathome.net
Floor 12 Posted 2008-05-07 16:30 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
```
@echo off&setlocal enabledelayedexpansion
set "str=ab"&set /a a=%random%%%60+1
:begin
set /a b=%random%%%2
set c=!str:~%b%,1!&set var=%var%!c!
set /a n+=1
if %n% lss %a% goto begin
echo The generated string for this time is:
echo %var%&set code=%var%
echo The total number of characters (excluding spaces) output below is 60:
set "str="&set n=0
:lp
if !n! lss 60 if defined var (
set /a b=%random%%%2
if !b! equ 0 (
set "b= "
) else (
set b=!var:~,1!&set /a n+=1
)
set str=%str%!b!
set var=%var:~1%
goto lp
)
echo.%str%
if !n! lss 60 set str=&set var=%code%&goto lp
pause>nul
```
If you want to achieve decremental output, it is difficult to meet the requirement that the total number of characters is 60. For example, when the originally generated string is: a, there will be at most one line and one character.

[ Last edited by zw19750516 on 2008-5-7 at 05:28 PM ]
批处理之家新域名:www.bathome.net
Floor 13 Posted 2008-05-07 16:45 ·  中国 上海 联通
初级用户
★★
Credits 153
Posts 68
Joined 2006-10-12 22:25
19-year member
UID 65507
From 上海
Status Offline
Originally posted by 26933062 at 2008-5-7 12:16:
What is required is randomness. If possible, it could be one line.
It should be randomly generating either a or b, generated one by one. The total number is 60.

You seem more like the LZ than the LZ...
个人主页-找餐厅:http://www.canting.cc
Floor 14 Posted 2008-05-07 17:55 ·  中国 山东 淄博 联通
银牌会员
★★★
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-5-7 04:30 PM:
@echo off&setlocal enabledelayedexpansion
set "str=ab"&set /a a=%random%%%60+1
:begin
set /a b=%random%%%2
set c=!str:~%b%,1!&set var=%var%!c!
set /a n+=1
if %n% l ...

Wow! Really amazing! Although this code still looks a bit challenging... ^_^
Floor 15 Posted 2008-05-07 19:44 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Reply to floor 12
Sorry, the answer is still incorrect. Maybe I didn't describe it clearly enough.
There should be no space directly above each letter.
Let me put it this way
Randomly generate the first letter. For example, if it's "a", write it to the new file. Then generate the second letter. If it's the same as the previous letter, write this letter directly below the previous one; otherwise, write it in the first line.

Reply to floor 13
What on earth...
致精致简!
Forum Jump: