windows本地评测批处理脚本
来源:互联网 发布:js鼠标点击拖动事件 编辑:程序博客网 时间:2024/04/29 21:18
当然还有将被评测的代码文件“代码.cpp”。
将下面的批处理代码复制进txt文件,改后缀名为.bat,放入文件夹。
@echo offstart /wait 获取时间.exe set t1=%errorlevel%代码 < data.in > 代码.outstart /wait 获取时间.exeset t2=%errorlevel%set /a t=%t2%-%t1%fc 代码.out data.out > nulif not errorlevel 1 (echo Accepted)if errorlevel 1 (echo Wrong Anwser)echo 运行时间:%t%mspause
其中包含获取运行时间的功能,所以要在文件夹中再放入一个c语言编译的“获取时间.exe”,其代码如下:
#include <windows.h>
#include<stdio.h>
int main(int argc, char** argv)
{
int t = GetTickCount();
printf("%d\n", t);
return t;
}
备注:这里的程序运行时间只能做大致参考,其结果非常不准确,原因是这个时间是程序运行前后时间差,而不是程序占用cpu的时间,其实这里面还包含了系统和其他程序运行的时间。
文件夹截图如下:
其中“生成随机数”文件夹先不用管。
现在将“代码.cpp”编译成“代码.exe”,运行上面的.bat批处理程序(我的是“进行!!测试.bat”),就会输出程序运行时间、AC/WA信息。
也可以把结果呈现为对话框形式,批处理代码如下:
@echo offstart /wait 获取时间.exe set t1=%errorlevel%代码 < data.in > 代码.outstart /wait 获取时间.exeset t2=%errorlevel%set /a t=%t2%-%t1%fc 代码.out data.out > nulif not errorlevel 1 start mshta vbscript:msgbox("运行时间:%t%ms,程序输出与data.out吻合",0,"Accepted")(window.close)&&exit start mshta vbscript:msgbox("运行时间:%t%ms,程序输出与data.out不吻合!!!!",0,"Wrong Answer")(window.close)&&exit
运行结果如下:
==========================================================================
这个功能可以用来出题或者进行本地程序对拍,个人感觉非常方便。
data.in是输入文件,它可以是手动编写的数据,但大多数情况下都是随机产生的。
data.out可以用别人正确的代码产生,或者自己编写一个暴力的程序来产生。
产生随机数据的程序如下:
#include <stdio.h>#include <stdlib.h>#include<cstring>#include <time.h> //用到了time函数long long w,m,sum;int main(){ srand(time(NULL)); //用时间做种,每次产生随机数不一样 int X=10,T=50000,n=1000; printf("%d\n",X); printf("%d %d\n",n,T); while(T--) { int lx=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); }}
上面的代码只是一个示例,不同题目输入数据格式不同,但一般都用到rand()函数。
同样,为了避免在c程序中与文件打交道,可以用批处理命令来将大量数据输出到文本文件中:
CreateData > data.out
其中CreateData是c语言编译的可执行文件。
- windows本地评测批处理脚本
- windows批处理脚本撰写
- Windows的批处理脚本
- windows批处理脚本
- Windows 批处理脚本整理
- windows批处理脚本
- Windows批处理脚本小记
- windows批处理脚本 --- 笔记
- windows 启动 oracle 批处理脚本
- Windows BAT批处理脚本教程
- windows Bat 批处理脚本 教程
- WINDOWS下批处理脚本命令
- Windows安全检查脚本 bat 批处理
- windows批处理网卡切换脚本
- 评测脚本
- Batch script in windows(批处理脚本)
- Windows的网络配置的批处理脚本
- Windows批处理脚本(BAT,CMD)简明教程
- [数据结构-树状数组小结]
- [数据结构-查询区间最小值小结(RMQ问题(Range Minimum Query))]
- hdu 4568 旅行商问题dp
- Linux命令——find
- POJ 2299 Ultra-QuickSort
- windows本地评测批处理脚本
- Linux下软链接与硬链接
- hdu4758 hdu2825 hdu4057 AC自动机与状态压缩dp的结合
- poj 2155 二维线段树
- CRC
- poj 2528 数的离散化+线段树
- poj 2352 树状数组
- poj 2823 线段树
- ES6中的高阶函数:如同 a => b => c 一样简单