介绍
有许多OJ平台及各大比赛的出题人需要出很多的测试数据,但却自己编不出来?
下面这些建议你看看
(虽然网上有很多其他的bat版随机测试数据编写器,但是我还是喜欢用我这种C++版的)
主程序
.in
文件生成(data_make_in.cpp
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include<math.h> #include<string> #include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #include<time.h> #define ll long long using namespace std; int R(int x){return (rand()*rand())%x+1;} string s="name"; void s70(){ FILE* lin=fopen(s.c_str(),"w"); fclose(lin); return ; } void s30(){ FILE* lin=fopen(s.c_str(),"w"); fclose(lin); return ; } void s00(){ FILE* lin=fopen(s.c_str(),"w"); fclose(lin); return ; } int main(){ int tt; int typ=tt=20; int len=s.size(); s+=char(tt/100+'0'); s+=char((tt/10)%10+'0'); s+=char(tt%10+'0'); s+=".in"; srand((unsigned)time(NULL)); while(typ--){ if(typ>=tt*70/100) s70(); else if(typ>=tt*30/100) s30(); else s00(); s[len]='0'; s[len+1]='0'+typ/10; s[len+2]='0'+typ%10; } return 0; }
|
在上方代码的标记位置修改测试数据组数以及题目名(仅支持英文)。
在上方代码留空的地方进行生成操作。注意 :输出需用 fprintf(lin,项目1,项目2)
,详情可自行搜索
.out
文件生成(data_make_out.cpp
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include<cstdlib> #include<iostream> #include<string> #include<cstring> #include<ctime> #include<cstdio> #include<windows.h> using namespace std; int main(){ string name,in=".in",out=".out",exe=".exe",exefile=".exe",infile=".in",outfile=".out"; int n; printf("请输入题目名:"); cin>>name; printf("请输入数据in个数:"); scanf("%d",&n); exefile.insert(0,name); infile.insert(0,name); outfile.insert(0,name); string cmd2="del ",cmd4="del "; for(int i=n;i>=1;i--){ string cmd1="copy ",cmd3="copy "; cmd1+=name; cmd1+=char(i/100+'0'); cmd1+=char((i/10)%10+'0'); cmd1+=char(i%10+'0'); cmd1+=in; cmd1+=" "; cmd1+=infile; system(cmd1.c_str()); system(exefile.c_str()); cmd3+=outfile; cmd3+=" "; cmd3+=name; cmd3+=char(i/100+'0'); cmd3+=char((i/10)%10+'0'); cmd3+=char(i%10+'0'); cmd3+=out; system(cmd3.c_str()); printf("NO.%d\n",i); } cmd2+=infile; cmd4+=outfile; system(cmd2.c_str()); system(cmd4.c_str()); return 0; }
|
上面的代码你不需要进行任何的改动,直接复制然后编译运行即可,照着运行要求进行就行
注意 :所有前面生成的所有.in
文件、正解的.exe
文件和上面这个.cpp
编译出来的.exe
文件都要放在同一目录下!!
注意 :正解需要用加上freopen
,输入文件名为 题目名+.in
,输出文件名为 题目名+.out
,更多有关内容可自行搜索
结果
运行完以上两个程序后在当前文件夹会出现测试数据,可压缩成 .zip
压缩文件进行其他操作
结尾
如果你觉得这篇文章写的很好,记得 转发