中国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-11-13 07:23
47,815 topics / 349,931 posts / today 1 new / 48,293 members
网络日志(Blog) » 523066680 Editing Area
Printable Version  36,111 / 42
Floor16 523066680 Posted 2009-08-23 07:19
银牌会员 Posts 1,133 Credits 2,361
```cpp
#include <Conio.h>
#include <graphics.h>
#include <stdlib.h>
#define closegr closegraph
#define NDOT 3


typedef struct
{
int a, b, x, y;
} DotInf;


void initgr(void) /* BGI initialization */
{
int gd = DETECT, gm = 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd, &gm, "");
}

void delta(DotInf dot, int c)
{
int i, j;
setcolor(c);
for (i = 0; i < NDOT; i++)
for (j = i + 1; j < NDOT; j++)
{
line(dot.x, dot.y, dot.x, dot.y);
}
}

int main(void)
{
int i, j, whi = 0, edotn = 0;
DotInf snk;
DotInf edot;
for (i = 0; i < 9; i++)
for (j = 0; j < NDOT - 1; j++)
{
edot.x = edot.y = 0;
}

initgr(); /* BGI initialization */

for (i = 0; i < NDOT; i++)
{
snk.a = snk.b = snk.x = snk.y = 200;
edot.x = edot.y = 200;
}
randomize();
while (!kbhit())
{
if (edotn < 9)
edotn++;
else
edotn = 0;
if (whi < NDOT)
whi++;
else
whi = 0;
for (i = 0; i < 400; i++)
delay(15);
if (edot.x != 0)
delta(edot, 0);
delta(snk, 2);

for (i = 0; i < NDOT; i++)
{
if ((snk.x == snk.a) && (snk.y == snk.b))
{
snk.a = rand() % 600 + 1;
snk.b = rand() % 400 + 20;
}
}
for (i = 0; i < NDOT; i++)
{
if (whi > i)
continue;
if (snk.x > snk.a)
snk.x--;
else if (snk.x < snk.a)
snk.x++;
else
{
if (snk.y > snk.b)
snk.y--;
else if (snk.y < snk.b)
snk.y++;
}

edot.x = snk.x;
edot.y = snk.y;

}


}

getch();
closegr(); /* Restore TEXT screen mode */
return 0;
}
```
Floor17 523066680 Posted 2009-08-23 07:20
银牌会员 Posts 1,133 Credits 2,361
```
@echo off
setlocal enabledelayedexpansion
mode con cols=25 lines=5
title %date%
set "str=xxxxxxxx"
:a
set t=%time:~0,8%
call :next
ping -n 3 127.1>nul
set "t= "
call :next
goto :a

:next
for /l %%a in (0,1,7) do (set num%%a=%%a)
set /a aa=8
:aa
set /a rand=%random%%%aa,aa-=1
set /a x=num%rand%,xb=x+1
set str=!str:~0,%x%!!t:~%x%,1!!str:~%xb%!
set num%rand%=!num%aa%!
ping -n 1 127.1>nul
cls
echo, %str%
if %aa% gtr 0 (goto :aa)
goto :eof
```

[ Last edited by 523066680 on 2009-8-23 at 07:22 ]
Floor18 523066680 Posted 2009-09-03 09:11
银牌会员 Posts 1,133 Credits 2,361
Decompose a natural number into n consecutive natural numbers.

```batch
@echo off
:a
set "inp="
set /p inp="input a number: "
set /a act=2,end=inp/2,inp*=10,the500=1,the001=1
:lp
set /a x=inp/act,xx=inp%%act,xxx=act%%2
if defined the%x:~-1%%xx%%xxx% (call :func %x:~-1%)
if %act% lss %end% (set /a act+=1 &goto :lp)
pause &goto :a

:func
set /a a=(x-%1)/10-(act-1)/2,b=(x+%1)/10+(act-1)/2
if %a% lss 0 (set /a end=0 &goto :eof)
for /l %%a in (%a%,1,%b%) do set /p= %%a<nul
echo,&echo, &goto :eof
```

Numbers with negative numbers in the composition:

```batch
@echo off
:a
set /p inp="input a number: "
set /a act=2,end=inp/2,inp*=10,the500=1,the001=1
:lp
set /a x=inp/act,xx=inp%%act,xxx=act%%2
if defined the%x:~-1%%xx%%xxx% (call :func %x:~-1%)
if %act% lss %end% (set /a act+=1 &goto :lp)
pause &set "inp=" &goto :a

:func
set /a a=(x-%1)/10-(act-1)/2,b=(x+%1)/10+(act-1)/2
for /l %%a in (%a%,1,%b%) do set /p= %%a<nul
echo,&echo, &goto :eof
```

List numbers around 1000 that cannot be split into n consecutive natural numbers:

```batch
@echo off
set /a inp=0,the500=1,the001=1
:a
set /a inp+=1,act=2,end=inp/2,inp*=10,have=0
:lp
set /a x=inp/act,xx=inp%%act,xxx=act%%2
if defined the%x:~-1%%xx%%xxx% (set /a inp/=10 &goto :a)
if %act% lss %end% (set /a act+=1 &goto :lp)
set /a inp/=10
echo,%inp%
if %inp% lss 1000 goto :a
pause
```
Floor19 523066680 Posted 2009-09-15 22:30
银牌会员 Posts 1,133 Credits 2,361
```vbscript
set wsx=createobject("wscript.shell")
if wscript.arguments.count = 0 then
wsx.run "cmd /c cscript " &wscript.scriptname & " 1 &pause>nul"
wscript.quit
end if

checkfile="test1.vbs"
argu=""
set start=wsx.exec("cscript " &checkfile &argu)
set errinfo=start.stderr
set echo=wscript.stdout

x=errinfo.readline

if x="" then
echo.writeline "No error information."
else
str=""
echo.writeline ""
t1=split(x,",")
tt1=split(t1(0),"(")
tt2=split(t1(1),")")
y=tt1(1) : x=tt2(0)
for i = 2 to x
str=str & " "
next
echo.writeline "Filename: " & tt1(0)
echo.writeline "ErrInfo : " & tt2(1)
echo.writeline "(Lines = " &y &" , cols =" &x & ")"
echo.writeline str & "↓"

set readx=createobject("scripting.filesystemobject").opentextfile(checkfile,1)
for i = 2 to y
readx.readline
next
echo.writeline readx.readline
if readx.atendofstream then
echo.writeline "Check Info: End of line."
else
for i = 1 to 4
if readx.atendofstream = false then
echo.writeline readx.readline
end if
next
end if
read.xclose
end if

echo.write vbcrlf &"Press any key to continue..."
echo.close
wscript.quit
```
Floor20 523066680 Posted 2009-11-20 20:09
银牌会员 Posts 1,133 Credits 2,361
Today is very boring...
@echo off
setlocal enabledelayedexpansion
for /l %%a in (1,1,40) do (set spc= !spc!)
set strx=%spc: =x%
for /l %%a in (1,1,20) do (set ln%%a=%spc%)
set /a a=-20
:a
set inp=%a:-=%
set /a n=inp*2,stra=(80-n)/2,la=(24-inp)/2,a+=2
for /l %%a in (1,1,1) do (ping -n 1 127.1>nul)
cls
for /l %%a in (1,1,%la%) do (echo, )
for /l %%a in (1,1,%inp%) do (echo,!spc:~-%stra%!!strx:~-%n%!)
if %a% geq 20 set a=-20
goto :a
Floor21 523066680 Posted 2010-01-06 19:34
银牌会员 Posts 1,133 Credits 2,361
read
Text: 523066680
First one today.
It can be regarded as a kind of note, just like a log
Not really sharing, because everyone will go through their own exploration process.

By the way, learn English, so I pull up the original help together

Parameters and corresponding examples:
-a array assign the words read to sequential indices of the array
variable ARRAY, starting at zero
Assign the input content to the sequential indices of the array according to the delimiter (space or tab, etc.), and consecutive spaces are also counted as 1 division.
After input, the array specification is the same as in C language, and it is expressed in the format of var, with subscripts starting from 0.
Directly echo $var is equivalent to echo ${var}
When echoing an array with subscripts, remember to add {} to express, for example, echo ${a}
Define array variable: read -a arr is okay; read -a arr is wrong.
But you can directly read arr, which is to directly assign a certain element of the array.

-d delim continue until the first character of DELIM is read, rather
than newline
That is, read input until the first character of DELIM is read, instead of ending with a newline. Of course, the "certain character" is not counted.
Test results:
1. After specifying a certain character, the carriage return is also read in, and it will not end due to the carriage return
(Hehe, I haven't tried to end with the carriage return character, I won't make + redundant)
2. -dstr does not reach the end of str, it is the end of s, so people say it is a character
3. -dx str ;# Turned n lines + input character ; echo $str will not output the newline
To echo "$str" will output the newline.

(The following are directly quoted from the help content if I don't know)
-e use Readline to obtain the line in an interactive shell
I don't know, it seems that the default is to end after reading a line? I will make up for it later when I know.

-i text Use TEXT as the initial text for Readline

-n nchars return after reading NCHARS characters rather than waiting
for a newline
rather than here means: instead of.
Read until the Nth character and then end~ instead of waiting for a new line.
The result is that pressing Enter will end in advance
I feel that the description is not strict. The actual rule is {If newline || the number of characters is n; then end}
(The help of this parameter once made me think that rather than means or)

-p prompt prompt is the meaning of prompt, that is, first display the "prompt" string, and then wait for you to input.
With the prompt option, there is no need to echo the prompt separately.

-r do not allow backslashes to escape any characters
backslash backslash "\";
escape escape; here means: escape
Translation: Do not allow backslashes to escape any characters.

-s do not echo input coming from a terminal
Do not display the characters being input from the terminal. (Just like when entering a password),
To be honest, I can't imagine the connection between -s and this function. Learning it is like reciting.

-t timeout time out and return failure if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
variable is the default timeout. TIMEOUT may be a
fractional number. If TIMEOUT is 0, read returns success only
if input is available on the specified file descriptor. The
exit status is greater than 128 if the timeout is exceeded
1. If a line of input is not completed (triggering the termination input condition) within timeout seconds, it will time out and exit + the command will return an
error code.
2. I can't see this sentence, but executing TMOUT=1, the command line exits after 1 second
3. The value of timeout can be a fractional number , of course, it is not really expressed in fractional notation
It is to tell you that you can use a non-integer, such as -t0.5 is to limit input within half a second.
4. If timeout is set to 0, it will only return success if input is available from the effective special file descriptor.
5. exceed exceed; if timed out, the exit status is greater than 128.
-u fd read from file descriptor FD instead of the standard input
I won't say, I don't know what fd is. Relevant information: http://baike.baidu.com/view/1303430.htm
"Under linux, all operations are on files, and the operations on files are realized by using file descriptors
(file descriptor). In the source code, fd is generally used as the identifier of the file descriptor."


# Still don't know the meanings of several parameters, so I will come back to modify them when I know... #


End: If read is not followed by a variable name, the value will be assigned to the REPLY variable,
However, if you give a new variable name, REPLY will not be updated synchronously.



+++++++++++++++++Learn some English+++++++++++++
#1 -e use Readline to obtain the line in an interactive shell
Baidu search:
obtain obtain; get
Example: He failed to obtain a scholarship. He didn't get a scholarship.

interactive interactive; interactive

#2 -n nchars return after reading NCHARS characters rather than waiting
for a newline

rather than : instead of

#3 -t timeout
time out and return if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
variable is the default timeout. TIMEOUT may be a
number. If TIMEOUT is 0, read returns success only
if input is available on the specified file descriptor. The
exit status is greater than 128 if the timeout is

failure n. failure
He was doomed to failure. He was doomed to failure

fractional adjective: small amount; fractional

exceed exceed
Floor22 523066680 Posted 2010-01-24 21:46
银牌会员 Posts 1,133 Credits 2,361
Originally, `read -n1` can read only one character, and pressing a key would proceed to the next line.
I wrote a loop with `read -n1`, which is to repeatedly perform this operation by pressing any key, in order to make the loop wait for my confirmation.

As a result, pressing the "right arrow key" caused the loop to run n times in a flash. It turns out that these direction keys, etc., press once and correspond to several characters.
It made me run the loop n times…… (Did it become that a key was pressed n times? O_o)

So I added `read -n9 -t0.1` before `read -n1`, that is:
After reading one character,
within 0.1 seconds, regardless of whether there are 9 characters or not, eat them all
(I thought that `-t0` could instantly eat them, but I found that there was still one key press, and there was a time difference for the several characters that appeared, so I used 0.1)


I tried it, and directly using `read -t0.1` to eat characters doesn't work. It only waits for 0.1 seconds and doesn't read characters
(Because by default, the Enter key is used as the end of input)
Logically, it would cause an infinite loop and not wait, but here it only cycled a few times continuously.
Almost forgot, originally there was a `read -n1` in each loop to read one character~.

At the same time, I felt that the `-n` option, when reading n characters, breaks the restriction of ending input with Enter.
`-t -n` is the "OR" restriction~ (timeout)||(when n characters are read) then end
=================================================================
Change it to exit when pressing the q key


[ Last edited by 523066680 on 2010-1-24 at 22:14 ]
Floor23 523066680 Posted 2010-03-14 22:27
银牌会员 Posts 1,133 Credits 2,361
Originally, using xcopy could update the backup directory system to my mobile hard drive. But xcopy only handles copying, so every time I back up, there are additions but no deletions. Although I could first delete everything and then xcopy, which saves code, copying takes more time. So I added a segment of code to delete the things that exist in the backup directory but not in the source directory. Using for combined with dir to traverse the directory tree. Judge if it's a directory, then rd the directory system; if it's a file, then delete (the judgment sentence if exist "%%a\"). But there was an error the first time. The reason was: Some main directories had already been deleted, so the subdirectories and files under them were also deleted, but the directories listed by dir were not updated and still listed their subdirectories, causing the error that subdirectories no longer existed but deletion was still continued. So I added another judgment before each deletion operation: whether the target exists. Features: If the destination disk used for backup doesn't exist, it will exit in advance. If it's executed successfully, a log of deleted files will be generated. Delete first, then xcopy.



I know some software can achieve this, but the advantage of batch processing is that I can implement some detailed operations by myself, such as the /exclude:cut.txt parameter, which is used to specify the file names or folders listed in the cut.txt text that are not to be copied.

[ Last edited by 523066680 on 2010-3-20 at 12:17 ]
Floor24 523066680 Posted 2010-04-13 11:14
银牌会员 Posts 1,133 Credits 2,361
```
@echo off
setlocal enabledelayedexpansion
::To reduce the judgment + the name number part is neat (uniform two-digit number), the number of files cannot be greater than 99, that is, 01-99 is specified
::Preliminary verification
if "%~1"=="" (
echo You didn't drag a file onto me, so the first parameter is empty, press any key to bye~
pause>nul
exit
) else (
if exist "%~1" (
echo The folder where the dragged file is located "%~dp1"
echo _
set /p "inp=Before batch renaming, please specify the name prefix:"
set /a n=1
set "nx=000!n!"
set "xformat=%~x1"
set "xpath=%~dp1"
) else (echo There is a parameter but it is not right, bye &pause>nul &exit)
)

::If %~1 is non-empty and exists, it will reach here
:main
if not "%~1"=="" (
if exist "%~1" (
echo The operation being performed: ren "%~nx1" "!inp!!n!%~x1%#"
ren "%~1" "!inp!!nx:~-2!%~x1%#"
set /a n+=1
set nx=000!n!
) else (echo "%~1" is not exist)
shift /1
goto :main
) else (
echo Now restore the format ren "%xpath%*%xformat%#" "*%xformat%"
ren "%xpath%*%xformat%#" "*%xformat%"
pause
exit
)
```
Floor25 yonghu111 Posted 2010-04-13 15:30
初级用户 Posts 57 Credits 90
Thanks for sharing!
Floor26 523066680 Posted 2010-05-23 18:47
银牌会员 Posts 1,133 Credits 2,361
Read the script, and you can continue to plot points and color by appending commands to script a.x for observation.

This is a prototype, identifying only three commands:
color red,green,blue
point x,y,z
sleep time



Compiled under Windows with Dev-CPP (including the glut library).

The following batch processing generates random commands to observe the effect


I think this will be a pretty good start~

[ Last edited by 523066680 on 2010-5-23 at 18:50 ]
Floor27 523066680 Posted 2010-06-09 19:38
银牌会员 Posts 1,133 Credits 2,361
```
@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::
:: Temporary notebook, code by [email protected]
::
:: Parameter: add Note content Add Note content to the note list
:: Parameter: del Number 1 Number 2 .... Delete the note with the specified number
:: Parameter is empty Directly read the note text
::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set notebook=notebook.x
set arg_del=del
set arg_add=add
set arg_=type

if not exist "%notebook%" (
echo %notebook% does not exist, will be created
type nul>>notebook.x
exit /b
)

if not defined arg_%1 (
echo Command %1 does not exist
exit /b
) else (
if "%1"=="" (goto :func_)
)

:read_it
::If the parameter is not empty, come here. Adding project numbers and deleting projects both need to read text information first
::text format: $number $date $note, range of number :
set /a note_n=0
for /f "tokens=1,2,*" %%a in ('type %notebook%') do (
set note_info_#%%a=%%b %%c
set /a note_n+=1
)
::Then jump to the function block
goto :func_%1


:func_
type %notebook%
exit /b

:func_del
set /a x=-1
if "%2"=="" (echo arg2 = NULL &exit /b)
if not defined note_info_#%2 (echo no this item. &exit /b)
::Assume that more than one item is deleted, the parameters are separated by spaces, and the total parameters are used as strings for judgment
for /f "tokens=1,*" %%a in ("%*") do (set note_items=%%b)
::Like 10, the deletion is 0. After simply replacing 0, it will also change. The subsequent judgment will delete, so it is dangerous. Add judgment factors
set note_items=#%note_items: =#%#
echo,>%notebook%
for /f "tokens=2,* delims==#" %%a in ('set note_info_#') do (
if "!note_items:#%%a#=!"=="!note_items!" (
set /a x+=1
set xnum= !x!
set xnum=!xnum:~-2!
echo !xnum! %%b>>%notebook%
) else (
echo Deleted item - %%a %%b
)
)
echo %notebook% rearranged, current situation :
type %notebook%
exit /b
:func_add
if "%2"=="" (echo Additional information is empty &exit /b)
set xnum= %note_n%
set xnum=!xnum:~-2!
set strnow=%*
::::cut string - "add "
set strnow=%strnow:~4%
(echo %xnum% %date:~0,10% %strnow%)>>%notebook%
echo %notebook% current situation :
type %notebook%
exit /b
```

Test:

c:\test>note add This is a test item
notebook.x current situation :

0 2010-06-08 Express delivery collection and delivery of goods not arrived
1 2010-06-08 Materials not counted
2 2010-06-09 Make a supplier address and phone information form
3 2010-06-09 This is a test item

c:\test>note del 1 2
Deleted item - 1 2010-06-08 Materials not counted
Deleted item - 2 2010-06-09 Make a supplier address and phone information form
notebook.x rearranged, current situation :

0 2010-06-08 Express delivery collection and delivery of goods not arrived
1 2010-06-09 This is a test item

c:\test>


[ Last edited by 523066680 on 2010-6-9 at 21:26 ]
Floor28 523066680 Posted 2010-07-13 17:36
银牌会员 Posts 1,133 Credits 2,361
I'm the kind who hasn't watched for dozens of episodes.
You know, it's really hard to watch online, flipping through one by one, so I decided to download all.
getpic.sh


Finished watching Bleach all at once, so then download Naruto.
Due to work, I often switch systems, sneaking around, so I also made a batch processing version:
Really envy that bash supports expansions like {1..4}=1 2 3 4..... When changing to batch processing, it becomes cumbersome.


Finally, looking at it with an image viewer was really uncomfortable, so batch import into web pages.
Put the pictures of one episode on one page, so just flip once per episode.



[ Last edited by 523066680 on 2010-7-13 at 17:46 ]
Floor29 523066680 Posted 2010-07-18 15:22
银牌会员 Posts 1,133 Credits 2,361
The execution order is: first MainGet.bat and then Act.bat. The other two are called.

MainGet.bat
First, obtain 1 - 10 pages with the list attached, where there are the sub - pages needed.


Act.bat
Responsible for extracting the list and sub - page addresses and handing them over to the download script.


downer.bat is called by Act.bat
Analyze the image links in the sub - page and download all of them. Wait, a side issue, why when i % 3 = 1 and 2, external calls for downloading are made.
You know, code speed>download speed, external call, multi - process download will not take up time.
When the remainder is 0, the current process downloads, this is for buffering. If all are called externally, there is no buffering, it will become a bomb - like script.


geter.bat
Called by downer.bat


[ Last edited by 523066680 on 2010 - 7 - 19 at 12:34 ]
Floor30 523066680 Posted 2010-07-30 20:18
银牌会员 Posts 1,133 Credits 2,361


[ Last edited by 523066680 on 2010-7-30 at 20:23 ]
Prev  1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023