中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-26 16:32
47,813 topics / 349,918 posts / today 0 new / 48,276 members
DOS批处理 & 脚本技术(批处理室) » [Help] Text output~
Printable Version  3,491 / 47
Floor1 pusofalse Posted 2008-05-06 22:44
银牌会员 Posts 646 Credits 1,604
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...
Floor2 bat-zw Posted 2008-05-07 11:00
金牌会员 Posts 1,276 Credits 3,105
```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 ]
Floor3 bat-zw Posted 2008-05-07 11:52
金牌会员 Posts 1,276 Credits 3,105
```@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
```
Floor4 26933062 Posted 2008-05-07 12:02
银牌会员 Posts 879 Credits 2,268
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 ]
Floor5 bat-zw Posted 2008-05-07 12:04
金牌会员 Posts 1,276 Credits 3,105
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?
Floor6 26933062 Posted 2008-05-07 12:07
银牌会员 Posts 879 Credits 2,268
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
Floor7 bat-zw Posted 2008-05-07 12:13
金牌会员 Posts 1,276 Credits 3,105
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.
Floor8 26933062 Posted 2008-05-07 12:16
银牌会员 Posts 879 Credits 2,268
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.
Floor9 bat-zw Posted 2008-05-07 12:47
金牌会员 Posts 1,276 Credits 3,105
```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
```
Floor10 26933062 Posted 2008-05-07 14:15
银牌会员 Posts 879 Credits 2,268
Have you tested the ls? What is needed is the format of the top post.
Floor11 bat-zw Posted 2008-05-07 15:31
金牌会员 Posts 1,276 Credits 3,105
&& 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 ]
Floor12 bat-zw Posted 2008-05-07 16:30
金牌会员 Posts 1,276 Credits 3,105
```
@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 ]
Floor13 uemuem Posted 2008-05-07 16:45
初级用户 Posts 68 Credits 153 From 上海
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...
Floor14 pusofalse Posted 2008-05-07 17:55
银牌会员 Posts 646 Credits 1,604
Originally posted by zw19750516 at 2008-5-7 04:30 PM:
Floor15 26933062 Posted 2008-05-07 19:44
银牌会员 Posts 879 Credits 2,268
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...
1 2 3 4  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023