Put "data.in" and "Data.out" text files in any folder, which represent input files and output files, respectively.
Of course there is the code file "code. cpp" that will be evaluated.
Copy the following batch code into the TXT file, and change the suffix to. bat and place it in the folder.
@echo offStart/wait gets the time.EXESett1=%ERRORLEVEL% Code< data.in > code. outStart/wait gets the time.EXESett2=%ERRORLEVEL%Set/A t=%T2%-%T1%FC Code. Out Data.out >nulif not ERRORLEVEL1 (EchoAccepted)if ERRORLEVEL1 (EchoWrong anwser)EchoRunning time:%t%msPause
This includes the ability to get run time, so you can put a C-language compiled "get time. exe" in the folder with the following code:
#include <windows.h><stdio.h>int main (intChar* * argv) { int t = GetTickCount (); printf ("%d\n", T); return t;}
The folders are as follows:
Where the "Generate random Numbers" folder does not have to be managed first.
Now compile "code. cpp" into "code. exe" and run the above. bat Batch program (my YES!!). Test. Bat "), it will output the program run time, AC/WA information.
You can also render the result as a dialog box, with the batch code as follows:
@echo offStart/wait gets the time.EXESett1=%ERRORLEVEL% Code< data.in > code. outStart/wait gets the time.EXESett2=%ERRORLEVEL%Set/A t=%T2%-%T1%FC Code. Out Data.out >nulif not ERRORLEVEL1StartMshta VBScript: MsgBox("Run Time:%t%ms, program output matches Data.out", 0, "Accepted") (window.close) &&Exit StartMshta VBScript: MsgBox("Running Time:%t%ms, program output and data.out do not match!!!" ", 0," wrong Answer ") (Window.close) &&Exit
The results of the operation are as follows:
==========================================================================
This function can be used to make a question or a local program to Pat, personal feeling very convenient.
Data.in is the input file, which can be manually written data, but in most cases it is randomly generated.
Data.out can be generated by someone else's correct code, or by writing a brute-force program.
The procedure for generating random data is as follows:
#include <stdio.h>#include<stdlib.h>#include<cstring>#include<time.h>//using the time functionLong Longw,m,sum;intMain () {Srand (Time (NULL));//use time to make a different number of random numbers each time . intx=Ten, t=50000, n= +; printf ("%d\n", X); printf ("%d%d\n", n,t); while(t--) { intLx=rand ()%n+1, Ly=rand ()%n+1, Rx=rand ()%n+1, Ry=rand ()%n+1; while(rx<lx| | ry<ly) {Rx=rand ()%n+1; Ry=rand ()%n+1;} printf ("C%d %d%d%d\n", Lx,ly,rx,ry); }}
The above code is just an example, the input data format is different for different topics, but the rand () function is generally used.
Similarly, to avoid dealing with files in a C program, you can use batch commands to output a large amount of data to a text file:
Createdata > Data.out
Where Createdata is the C language-compiled executable file.
Windows Local Evaluation Batch script